Prev: How to make a recording from a digital source (fiber) using an Intel 2007 MacBook Pro?
Next: How to make a recording from a digital source (fiber) using anIntel 2007 MacBook Pro?
From: thepixelfreak on 25 May 2010 13:03 I've noticed some differences in /bin/sh and /bin/bash shell script execution. I'm wondering if anyone knows the differences between what should be the same gnu bash interpreter? I have a script that changes the color of text in Terminal.app. The script works (well, the ANSI escape sequences work) with /bin/sh but fail with /bin/bash (they are the VERY SAME version of bash). e.g. sh-3.2# echo $SHELL /bin/bash The following prints 'Tu' in red in a terminal window. sh-3.2# /bin/sh sh-3.2# echo '\033[1;31mTu\033[0m' Tu but fails with /bin/bash sh-3.2# /bin/bash sh-3.2# echo '\033[1;31mTu\033[0m' \033[1;31mTu\033[0m <---------- escape sequences aren't expressed. YET... sh-3.2# /bin/sh --version GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0) sh-3.2# /bin/bash --version GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0) AND. sh-3.2# diff /bin/bash /bin/sh Binary files /bin/bash and /bin/sh differ sh-3.2# cmp /bin/bash /bin/sh /bin/bash /bin/sh differ: char 24, line 1 I see from the man page: "If bash is invoked with the name sh, it tries to mimic the startup behavior of historical versions of sh as closely as possible, while conforming to the POSIX standard as well." I've tested this by copying /bin/bash to /tmp/sh and it doesn't make a difference. The /bin/bash binary fails while /bin/sh works. Any idea what's going on here? -- thepixelfreak
From: Jim Gibson on 25 May 2010 14:38 In article <2010052510030316807-not(a)dotcom>, thepixelfreak <not(a)dot.com> wrote: > I've noticed some differences in /bin/sh and /bin/bash shell script > execution. I'm wondering if anyone knows the differences between what > should be the same gnu bash interpreter? I have a script that changes > the color of text in Terminal.app. The script works (well, the ANSI > escape sequences work) with /bin/sh but fail with /bin/bash (they are > the VERY SAME version of bash). e.g. > > sh-3.2# echo $SHELL > /bin/bash > > The following prints 'Tu' in red in a terminal window. > > sh-3.2# /bin/sh > sh-3.2# echo '\033[1;31mTu\033[0m' > Tu > > but fails with /bin/bash The /bin/bash and /bin/bash files are separate files, although both seem to be based on bash. On my system (10.6.3): % ls -il /bin/*sh 348198082 -rwxr-xr-x 1 root wheel 1346544 Feb 4 16:41 /bin/bash* 348163684 -rwxr-xr-x 2 root wheel 767200 Feb 10 21:54 /bin/csh* 338032728 -r-xr-xr-x 1 root wheel 2186880 May 18 2009 /bin/ksh* 348198128 -r-xr-xr-x 1 root wheel 1346624 Feb 4 16:43 /bin/sh* 348163684 -rwxr-xr-x 2 root wheel 767200 Feb 10 21:54 /bin/tcsh* 338033955 -rwxr-xr-x 1 root wheel 1597200 May 10 2009 /bin/zsh* Note the different inode numbers for bash and sh and that the link numbers are 1 for each. (Contrast with csh and tcsh, which are actually the same file). Also note that even if /bin/bash and /bin/sh were the same file, they can exhibit different behavior if invoked differently, as a program can determine the command used to execute it. You can get echo to interpret escape sequences by including the -e option, although this is not documented in 'man echo' in either shell. So this works under bash: echo -e '\033[1;31mTu\033[0m' (but prints the '-e' under sh!). > > Any idea what's going on here? Not really, except that echo is a built-in command, depends on the shell of which it is a part, and bash and sh are different. -- Jim Gibson
From: Jolly Roger on 25 May 2010 21:37 In article <2010052510030316807-not(a)dotcom>, thepixelfreak <not(a)dot.com> wrote: > I've noticed some differences in /bin/sh and /bin/bash shell script > execution. I'm wondering if anyone knows the differences between what > should be the same gnu bash interpreter? I have a script that changes > the color of text in Terminal.app. The script works (well, the ANSI > escape sequences work) with /bin/sh but fail with /bin/bash (they are > the VERY SAME version of bash). e.g. Bash is a superset of sh. -- Send responses to the relevant news group rather than email to me. E-mail sent to this address may be devoured by my very hungry SPAM filter. Due to Google's refusal to prevent spammers from posting messages through their servers, I often ignore posts from Google Groups. Use a real news client if you want me to see your posts. JR
From: thepixelfreak on 26 May 2010 15:17 On 2010-05-25 11:38:39 -0700, Jim Gibson <jimsgibson(a)gmail.com> said: > > Note the different inode numbers for bash and sh and that the link > numbers are 1 for each. (Contrast with csh and tcsh, which are actually > the same file). Also note that even if /bin/bash and /bin/sh were the > same file, they can exhibit different behavior if invoked differently, > as a program can determine the command used to execute it. > > You can get echo to interpret escape sequences by including the -e > option, although this is not documented in 'man echo' in either shell. > > So this works under bash: > > echo -e '\033[1;31mTu\033[0m' Yea, I know of the -e. Doesn't seem very portable. > > (but prints the '-e' under sh!). > >> >> Any idea what's going on here? > > Not really, except that echo is a built-in command, depends on the > shell of which it is a part, and bash and sh are different. they clearly behave differently, but GNU would have you think they are the very same binary. sh-3.2# /bin/sh --version GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0) sh-3.2# /bin/bash --version GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0) -- thepixelfreak
From: thepixelfreak on 26 May 2010 15:18
On 2010-05-25 18:37:22 -0700, Jolly Roger <jollyroger(a)pobox.com> said: > In article <2010052510030316807-not(a)dotcom>, > thepixelfreak <not(a)dot.com> wrote: > >> I've noticed some differences in /bin/sh and /bin/bash shell script >> execution. I'm wondering if anyone knows the differences between what >> should be the same gnu bash interpreter? I have a script that changes >> the color of text in Terminal.app. The script works (well, the ANSI >> escape sequences work) with /bin/sh but fail with /bin/bash (they are >> the VERY SAME version of bash). e.g. > > Bash is a superset of sh. Really? sh-3.2# /bin/sh --version GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0) sh-3.2# /bin/bash --version GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0) -- thepixelfreak |