1827952 Members
3301 Online
109973 Solutions
New Discussion

Re: script reference

 
SOLVED
Go to solution
Ngoh Chean Siung
Super Advisor

script reference

Hi,

1) May I know any website that I can refer to learn the basic of shell script?

2) As I know, there are many types of script exp: korn shell, bourne shell, c, posix, pearl and etc. What is the main different for these script? Only different in syntax? If there is a scipt, how to determine what type of script being used?

regards.

regards
9 REPLIES 9
Jan de Haas_3
Frequent Advisor

Re: script reference

The following URL is quite good for shell scripting :
http://www.dartmouth.edu/~rc/classes/ksh/print_pages.shtml

What scripting language you use depends on what you want to accomplish. 'Normal' shell scripts written for korn, bourne, c, posix and bash are generally useful on every *nix system since they all have at least one of these shells already installed.

korn, posix and bash are (I think) about 99% compatible and a superset of the bourne shell. So bash or POSIX shell would be a good place to start with.

If you want to create more complex administration tools or want to start CGI scripting, you can also have a look at PERL or Python.

Usually a script written for a certain shell starts with a '#!' as the first line.

I recommend starting out with standard shell scripting before getting into PERL or Python though.

Hope this helps,
Jan.
Muthukumar_5
Honored Contributor

Re: script reference

1) Lots of sites there.

http://mercury.chem.pitt.edu/~sasha/LinuxFocus/English/September2001/article216.shtml
http://vertigo.hsrl.rutgers.edu/ug/shell_help.html
http://heather.cs.ucdavis.edu/~matloff/UnixAndC/Unix/CShellII.html

2) Shell scripting is differing based on supported operation and syntax. To determine the shell script type then,

open the script file with editor or cat
see the first line of #!

That shell inclusion is saying the shell type. You can use file <script> to know the shell type.

Difference between shell scripting is as,
http://www.softlab.ece.ntua.gr/facilities/documentation/unix/shelldiff.html#5
http://www.unix.com/archive/index.php/t-12274.html

hth.
Easy to suggest when don't know about the problem!
Bharat Katkar
Honored Contributor

Re: script reference

One more for you:
http://www.emu.edu.tr/english/facilitiesservices/computercenter/bookslib/
Regards,
You need to know a lot to actually know how little you know
Ngoh Chean Siung
Super Advisor

Re: script reference

Hi,

Thanks for your reply.

When I create a new user thru SAM, the Start-up Program that I choose is /usr/bin/sh. This means bourne shell, right? Can this user write a script without the heading like #! because the system will act it as bourne sheel?

regards.
Bharat Katkar
Honored Contributor

Re: script reference


/usr/bin/sh is POSIX shell which is default on HPUX.
/usr/old/bin/sh is bourne shell.

If you would like you use default shell then you don't have to specify starting line as #!/usr/bin/sh it will be POSIX by defualt.

If the use wants to use different shell other than POSIx then he need to mention the same in the first line of his script as:

#!/usr/bin/ksh

This will use korne shell.

Regards,


You need to know a lot to actually know how little you know
Muthukumar_5
Honored Contributor

Re: script reference

If you did not specify any shell in that scripting with #! then default shell of echo $SHELL will be undertaken. To override that you can change with that #! inclusion.

hth.
Easy to suggest when don't know about the problem!
James R. Ferguson
Acclaimed Contributor

Re: script reference

Hi:

If you haven't already noticed, the standard shell for HP-UX users is '/usr/bin/sh', whereas the REQUIRED shell for root is /sbin/sh'.

THe difference is that '/usr/bin/sh' has been compiled with dynamic link libraries whereas '/sbin/sh' uses only static ones.

NEVER change root's shell. The '/usr' filesystem isn't mounted during the early stages of system startup and any shell that needs needs the dynamic libraries therein would not be able to link to them. If you did this for the root user, you would find that your system was unbootable.

Use the '/usr/bin/sh' for all other non-root users. Using the dynamically linked, shared libraries provides a better memory footprint than having the static structure of '/sbin/sh'.

As already, noted, both '/sbin/sh' and '/usr/bin/sh' are POSIX shells. The old Bourne shell lives as '/usr/old/bin/sh'. You also have '/usr/bin/ksh' which is Korn88 and '/usr/dt/bin/dtksh' which is Korn93. A '/usr/bin/csh' shell is also available.

A very good site for shell scripts and tips is:

http://www.shelldorado.com/

A guide to shells can be found here:

http://docs.hp.com/en/B2355-90046/index.html

All shell scripts start with a declaration of the shell interpreter, clearly identifing the shell in use, like this:

#!/usr/bin/sh
#!/usr/bin/ksh
#!/usr/dt/bin/dtksh

Regards!

...JRF...
Ngoh Chean Siung
Super Advisor

Re: script reference

Hi,

I hv gone thru HP guide book on shell and found below table:

Table 1-2. Shell File Names and Default Prompts
Shell File Name Prompt
Bourne /bin/sh
POSIX /bin/posix/sh
Korn /bin/ksh
Key /usr/bin/keysh
C /bin/csh
Restricted Bourne /bin/rsh
Restricted Korn /bin/rksh

1) By default, all HP servers shell is POSIX, right? I think POSIX shell is /bin/sh. But why the above statement mentioned the POSIX is /bin/posix/sh?

2) By default, what is the shell that come together with the HP machine?

3) What is the shell name for bash, tcsh, zsh, rc and es? How about the shell name for pearl script?

regards.
James R. Ferguson
Acclaimed Contributor
Solution

Re: script reference

Hi (again):

1A. Yes, by default, the standard HP-UX shell is the POSIX shell -- either '/usr/bin/sh' for non-root users or '/sbin/sh' for the root. Please re-read my first response, above, for more details and the importance of maintaining this relationship.

1B. The '/bin' path, as in '/bin/sh' translates to the path '/usr/bin'. '/bin' is known as a "transition link". It arises at the time HP-UX 10.0 was released. At that time, the filesystems were reorganized into what you presently see. The model adopted paralleled AT&T SVR4 UNIX.

If you are interested in more of the details, see the "HP-UX 10.0 File System Layout White Paper" here:

http://www.docs.hp.com/en/5963-8942/index.html

While transition links still exist, you are STRONGLY encouraged NOT to use them, Thus, instead of coding '/bin' you should write '/usr/bin'. Transition links will disappear eventually.

2. As noted, while the standard shell is the POSIX shell; there is also the Korn shell (/usr/bin/ksh & /usr/dt/bin/dtksh for Korn-88 and Korn-93 implementations); and the C-shell (/usr/bin/csh) available as standard HP-UX shells. The very, old, Bourne shell can still be found as '/usr/old/bin/sh' but is virtually useless.

3. Other shells have been ported to HP-UX. The "Boune-Again_Shell" ('bash') is one popular one. Generally, these, and others often would be installed in '/usr/bin'. Exactly where they live matters less than the fact that the scripts that use them would declare their interpreter with the "she-bank" sequence -- "#!/usr/bin/bash" for instance, to tell that the script is a 'bash' shell script. The "she-bang" characters (#!) tell the kernel that what follows is the interpreter, or program to use.

Perl is far, far more than a shell language. It is an extremely powerful programming language which draws from the C language, the shell, 'awk' and 'sed'. It has one of the most powerful regular expression engines of any language available. It is generally loaded in '/usr/bin' or in '/opt'. Regardless of where it lives, a perl program also begins with something like "#!/usr/bin/perl" to declare that the program that follows is perl and where to find the perl executables. You can scratch the surface by starting your exploration here, for example:

http://www.perl.org/

Regards!

...JRF...