Found glich in 'bash'-shell !!!


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Found glich in 'bash'-shell !!!
# 1  
Old 04-16-2009
Found glich in 'bash'-shell !!!

Check this:
Code:
alias ec=/usr/bin/echo
src> ((1)) && { ec "true"; ((0)) && { ec "deep true"; }; } || { ec "false"; ((1)) && { ec "deep false"; }; }
true
false
deep false

src> if ((1)); then { ec "true"; ((0)) && { ec "deep true"; }; } else { ec "false"; ((1)) && { ec "deep false"; }; } fi
true

It is in bash
On first line, it seems, the shell loosing the stack, relating the or-'||' to the internal false-((0))

Is it for everyone, or only in our system?
Code:
src> bash -version
GNU bash, version 2.05.0(1)-release (sparc-sun-solaris2.9)
Copyright 2000 Free Software Foundation, Inc.

# 2  
Old 04-17-2009
First: before you report an alleged "glitch", try it again with a current version of the software. BASH is already up to 4.00
Second, it's not only your system, because it's not a glitch. Just because it didn't do what you expected doesn't mean it didn't do what is correct.
Code:
((1)) &&                        # True, and forces the next part to be evaluated.
{ ec "true";                    # returns true
  ((0)) && { ec "deep true"; }  # false, so the second part is not evaluated. This
                                # also means that the outer block counts as false
; } ||                          # First part is false ( true && false == false ),
                                # so the second part gets evaluated
{ ec "false";                   # returns true
  ((1)) && { ec "deep false"; } # First part is true, so the second is evaluated too.
; }

Addendum: Just tried it on different OS/shell combinations: it's the same using ksh88 on both HP-UX 11.11 and 11.31, bash 3.2 on HP-UX 11.31, ksh93 and bash 3.2 on Linux, and zsh 4.3.4 on Linux

Last edited by pludi; 04-17-2009 at 04:13 AM.. Reason: Additional Information
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to skip if file not found in bash?

Hello, I have a question regarding while loop and existence of files. I am running under ubuntu 18.04 bionic, have around fifty video files inside the directory. script: for file in *.mp4 do /root/bin/ffmpeg -i $file \ -i $(basename "${file/.mp4}").bs.srt \ -i $(basename... (12 Replies)
Discussion started by: baris35
12 Replies

2. UNIX for Advanced & Expert Users

Has AudioScope found a bug in bash 4.4.5?

Using AudioScope.sh on Ubuntu 17.04 from a live DVD disc I came across an error. Consider the code below it is a MUCH shortened version of the KEYBOARD input in AudioScope. #!/bin/bash bash --version uname -a status=0 KEYBOARD() { read -r -p "Enter QUIT or EXIT to quit:- " kbinput if ||... (11 Replies)
Discussion started by: wisecracker
11 Replies

3. Red Hat

-bash: sendmail: command not found

Hello Experts, I have been trying to send a test mail in our linux server with sendmail command.But I am getting command not found error message. -->when I tried whether sendmail installed or not with the command rpm -qa sendmail* I got the below, sendmail-cf-8.14.4-8.el6.noarch... (26 Replies)
Discussion started by: Devipriya Ch
26 Replies

4. Shell Programming and Scripting

-bash-3.2$: not found

I am wondering if someone can help me out. I am new to oracle and given a task to install Oracle 11g on Solaris. I am running into some major problems since last week since I can't seem to get it to work. I can't start GUI, tried different blogs but no luck. Then, I decided to install it in a... (4 Replies)
Discussion started by: newborndba
4 Replies

5. UNIX for Dummies Questions & Answers

File Not found - Bash script

I'm facing issues in executing the bash script of mine. This script will pick the latest file received and connects SFTP server and files is placed on this remote server. Error message Enter password: "File movement" sftp> cd Test sftp> put Test_File_201309.txt File "Test_File_201309.txt"... (6 Replies)
Discussion started by: parpaa
6 Replies

6. Shell Programming and Scripting

"Command not found" doing a while loop in bash/shell

i=0 numberofproducts=${#urls} #gets number of entries in array called "urls" numberofproductsminusone=`expr $numberofproducts - 1` #-subtract by one while do wget ${urls} i=$(( $i + 1 )) sleep 10 done I'm getting an error ./scrape: line 22: [0: command not found that... (3 Replies)
Discussion started by: phpchick
3 Replies

7. UNIX for Dummies Questions & Answers

Im new to bash scriping and i found this expression on a bash script what does this mean.

# check host value regex='^(||1|2|25)(\.(||1|2|25)){3}$' if ')" != "" ]; then if ]; then echo host $host not found exit 4 fi elif ]; then echo $host is an invalid host address exit 5 fi espeacailly the top regex part? ---------- Post updated at 06:58 PM ---------- Previous update was... (1 Reply)
Discussion started by: kevin298
1 Replies

8. Shell Programming and Scripting

bash:vi:command not found

I downloaded and installed "Cygwin yesterday onto my PC running Windows XP. When I tried to type "vi" in Cygwin's window, I got the following message bash: vi: Command not found What shud i do inorder to get into vi editor Thanks (10 Replies)
Discussion started by: bobby1015
10 Replies

9. Shell Programming and Scripting

rm:command not found in linux Bash shell script

Hi All, Linux lxs3er06 2.6.9-67.ELsmp #1 SMP Wed Nov 7 13:58:04 EST 2007 i686 i686 i386 GNU/Linux Issue: While executing shell scripts in bash shell, following error messages are thrown: rm:command not found On doing little investigation, I added '/bin' to $PATH and on doing echo... (9 Replies)
Discussion started by: a1_win
9 Replies

10. Shell Programming and Scripting

#!/bin/bash and #1bin/sh command not found error on mac osx terminal/shell script

i am having a weird error on mac os x running some shell scripts. i am a complete newbie at this and this question concerns 2 scripts. one of which a friend of mine wrote (videochecker.sh) a couple weeks ago and it's been running fine on another machine. then last week i wrote capture.sh and it... (2 Replies)
Discussion started by: danpaluska
2 Replies
Login or Register to Ask a Question