Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Run the bash shell in su mode' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Run the bash shell in su mode
Authored by: evansj on May 12, '04 04:03:46PM
bash and sh are actually the same binary.

$ diff -s `which bash sh`
Files /bin/bash and /bin/sh are identical
Although for some reason it's two copies, rather than one symlinked or hard linked to the other:

$ ls -li `which bash sh`
2821956 -rwxr-xr-x  1 root  wheel  603488 16 Mar 10:08 /bin/bash
2821939 -r-xr-xr-x  1 root  wheel  603488 16 Mar 10:08 /bin/sh
(the first number is the inode number)

[ Reply to This | # ]
Run the bash shell in su mode
Authored by: rhowell on May 12, '04 04:27:52PM

If they're identical files then they should give identical output when they're run. They don't. They're doing something differently. How do they do that?



[ Reply to This | # ]
Run the bash shell in su mode
Authored by: wombat on May 12, '04 04:58:01PM

It looks at the name of what's being executed (argv[0]) and makes its decision appropriately.



[ Reply to This | # ]
Run the bash shell in su mode
Authored by: evansj on May 13, '04 09:53:28AM
Spot on. 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.
There are a few specific behaviour changes documented in the man page, so man bash if you're interested.

[ Reply to This | # ]
broken hard links
Authored by: sjk on May 13, '04 12:49:34AM

I noticed that after installing one of the 10.3.x updates (.2 or .3) /bin/bash and /bin/sh were no longer hard linked, nor were other files in /bin and /usr/bin that previously had been. I'm convinced it's a side effect of installing certain dot-release updates (which I also noticed between some 10.2 releases), but it didn't happen with 10.3.1. My unconfirmed suspicion is that under certain conditions update_prebinding is responsible for making separate versions of system binaries that were originally hard linked.



[ Reply to This | # ]