Operating System - HP-UX
1829121 Members
2184 Online
109986 Solutions
New Discussion

scripts running as /bin/sh

 
SOLVED
Go to solution
brian_31
Super Advisor

scripts running as /bin/sh

Hi All:

We have several scripts and codes running on 11.0. The developers somehow prefer /bin/sh to run their programs from. I welcome all the gurus to comment on this practise.

Thanks
Brian.
14 REPLIES 14
Steven Sim Kok Leong
Honored Contributor

Re: scripts running as /bin/sh

Hi,

/usr/bin/sh (bourne shell) is the most basic shell that comes with all OSes. Thus, using this shell makes it portable across UNIX platforms.

If say you use /usr/bin/ksh and you want to port the script to Solaris, the additional effort to install the korn shell is needed.

Also, because it has less fanciful stuff, I believe the binary is smaller and more efficient.

Portability and less resource intensive.

Hope this helps. Regards.

Steven Sim Kok Leong
PIYUSH D. PATEL
Honored Contributor

Re: scripts running as /bin/sh

Hi,

Remember some things :

for ROOT always use /sbin/sh

You can /bin/sh for the users- there are no issues. You can also use /usr/bin/ksh ( Korn shell ) and /usr/bin/sh ( Bourne shell )for the users which givves you other advantages also.

Piyush


MANOJ SRIVASTAVA
Honored Contributor

Re: scripts running as /bin/sh

Hi Brian


You may like at the following :


http://www.uswebsites.com/support/cgi_scripts.shtml

http://google.yahoo.com/bin/query?p=developers+prefer+%2fbin%2fsh&hc=0&hs=0


It is more of a legacy , than any thing else .


Manoj Srivastava
A. Clay Stephenson
Acclaimed Contributor

Re: scripts running as /bin/sh

It makes no difference; these are identical versions of the POSIX shell. The Bourne shell is /usr/old/bin/sh. I suppose that my only objection is that /usr/bin/sh is the more 'standard' location but almost every UNIX box has a copy of sh in both /bin and /usr/bin. The real problem occurs if your developer's are using /bin/sh in the mistaken assumption that this is the Bourne shell.
If it ain't broke, I can fix that.
Enbin Hu
Advisor

Re: scripts running as /bin/sh

Brian,

On HPUX, the /bin/sh is a hard linked to /usr/bin/sh. It's the POSIX shell, I believe it's the default shell. In may areas, it is similar to the Korn shell. e.g. it has shell history, support job control and other stuffs.

If you need a comparision of various shells on HP, try the "man sh".

Hope it helps.
Peter Kloetgen
Esteemed Contributor

Re: scripts running as /bin/sh

Hi Brian,

/usr/bin/sh on HP-UX is the POSIX shell which is allmost the same than Korn shell.

/usr/bin/ksh is the Korn shell, very similar to POSIX shell

/sbin/sh is the superuser shell, should be the shell for root on every computer!

/usr/bin/csh the c- shell, which uses a different syntax, near to the programming language C.

/usr/old/bin/sh on HP-UX the Bourne shell, which is very old and not comfortable at all, no history, no file name generation and so on....

To get scripts, which run not platform dependant, you could use /usr/bin/ksh, which is available on allmost every platform. Remember, not every shell has the same syntax, but POSIX and Korn shell have.

Allways stay on the bright side of life!

Peter
I'm learning here as well as helping
Steven Sim Kok Leong
Honored Contributor

Re: scripts running as /bin/sh

Hi,

Oops, I have made a mistake. As indicated by the rest, it is the POSIX shell, not the Bourne shell.

I personally still prefer /usr/bin/sh because it is available on default across Unixes and Linuxes. Makes it easier for me to port it across platforms. If I use bash (bourne-again shell, should be right this time ;) ), then I have to specifically install it on the other Unix platform that does not support it by default.

Steven Sim Kok Leong
Helen French
Honored Contributor

Re: scripts running as /bin/sh

Just do 'ls -al' at the root prompt, you will find actually the /bin is linked to /usr/bin. So it doesn't make any difference if you use /bin/sh or /usr/bin/sh. The thing is /usr/bin/sh is the more acceptable standard path.
Life is a promise, fulfill it!
S.K. Chan
Honored Contributor

Re: scripts running as /bin/sh

After all that's been said I prefer to use /usr/bin/sh as the path for portability.
Carlos Fernandez Riera
Honored Contributor

Re: scripts running as /bin/sh

See this:

systemname>ll -d /bin /usr/bin /sbin
lr-xr-xr-t 1 root sys 8 Mar 6 08:52 /bin -> /usr/bin
dr-xr-xr-x 12 bin bin 3072 Apr 29 05:08 /sbin
dr-xr-xr-x 6 bin bin 10240 Jun 3 05:11 /usr/bin
systemname>ll -d /bin/sh /usr/bin/sh /sbin/sh
-r-xr-xr-x 2 bin bin 221184 Apr 23 2001 /bin/sh
-r-xr-xr-x 1 bin bin 421888 Apr 23 2001 /sbin/sh
-r-xr-xr-x 2 bin bin 221184 Apr 23 2001 /usr/bin/sh


/bin is a transition link to /usr/bin. It could be removed in any version. /bin/sh /usr/bin/sh is the same.

see man tlinstall tlremove.
unsupported
Bill Hassell
Honored Contributor
Solution

Re: scripts running as /bin/sh

/bin (and /lib) as mentioned do not exist on HP-UX (or Solaris for that matter). The industry standards (SysV.4 layout) about 10 years ago decided that /bin and /lib need to be migrated along with many other directory names and files. However, Unix applications tend to lag behind by about 5-8 years in following industry stadards so HP added the transition link concept, a symbolic link that replaces the old directory with a pointer to the new (preferred) one.

There is good and bad news with that: the good news is that old scripts will still run as usual (assuming they have the #/bin/sh header), and there are many flavors of Unix that still don't conform so the scripts will still work.

The bad news is that /bin/sh 'looks' like the Bourne shell and this scares users into using good old ksh. Also, changing the shebang (the #!/ header that specifies which interpreter to use) to #!/usr/bin/sh may break the script on other platforms. And transition links are optional--which means that a new administrator may look at the industry standards and decide to remove the transition links, thus breaking many scripts.

The future of transition links is not guarenteed! A new version of HP-UX may default to no links by default, and further revisions may not provide them.

One note about POSIX shells: HP-UX POSIX shell (which is stored in two formats in /usr/bin and /sbin) is one of many 'POSIX' shells. The Korn shell (as well as bash) are POSIX compliant which is why the vast majority of ksh and bash scripts run just fine using /usr/bin/sh. There is a great list that defines the differences (not many and pretty esoteric) in the 10.xx Release Notes in /usr/share/doc. For instance, ulimit has full functionality in the HP POSIX shell and bash (type ulimit -a) but ksh does not.


Bill Hassell, sysadmin
RikTytgat
Honored Contributor

Re: scripts running as /bin/sh

Hi,

Indeed, all are POSIX shells.

One thing to add, maybe. The 'superuser shell', /sbin/sh, is a statically linked POSIX shell. This is required for running a shell in single user mode (i.e. when /usr is not mounted and the shared libraries are not accessible).

Rik.
Giri Sekar.
Trusted Contributor

Re: scripts running as /bin/sh

Hi:

/bin/sh is never the right path. It should be /usr/sbin/sh and the same applies to /lib also. Take a case where an administrator may run "tlremove" and all the /bin codes would break. As Bill pointed out it is a mere symbolic link for old codes.

Giri Sekar.
"USL" Unix as Second Language
brian_31
Super Advisor

Re: scripts running as /bin/sh

Hi

Thanks for your time. It was a great learning experience. I never knew a command called "tlremove" before. I will make sure the guys here stick to /usr/bin/sh.

Thanks again
Brian