Operating System - HP-UX
1819794 Members
3192 Online
109607 Solutions
New Discussion юеВ

Korn Shell Programming on hp-ux 11i

 
Jackie Marmen
Occasional Contributor

Korn Shell Programming on hp-ux 11i

The default shell for our hp-ux users is Posix at login time, but we write all our scripts using the Korn shell. A menu script is executed in all users' .profile so they cannot get to the unix prompt, and the Korn shell is invoked by using the #!/bin/ksh as the first line in this menu script. Should the first line of all other scripts called by this menu script also have #!/bin/ksh as the first line, or does this cause the Korn shell to be executed repeatedly, resulting in wasted system resources for that session ?
5 REPLIES 5
John Dvorchak
Honored Contributor

Re: Korn Shell Programming on hp-ux 11i

Is there a reason why you just can't usermod all of the users to use the ksh?

If not I wouldn't worry about it, as good practice dictates that you specify the shell in the first line of any script.
If it has wheels or a skirt, you can't afford it.
S.K. Chan
Honored Contributor

Re: Korn Shell Programming on hp-ux 11i

No, having that line in the shell script simply means "the file will be executed in Korn shell". Without that line the file will be executed in whatever shell you're in at the point of calling the script. It's mainly for portability.
Frank Slootweg
Honored Contributor

Re: Korn Shell Programming on hp-ux 11i

Your scripts *should* (not must) have the correct "#! ..." line. If they don't, they will fail sooner or later and probably in hard to trace and inconvenient ways. [1]

And by the way, it is /usr/bin/ksh, not /bin/ksh. On *most* *HP-UX* systems, the latter is symbolically linked to the former, but relying on that is another accident waiting to happen.

An yet another by the way: On HP-UX there is no good/valid reason to use the Korn shell instead of the POSIX shell, because the latter is a superset of the former.

[1]:

ws$ cat doit
# This is a ksh script.
VARIABLE=content
ws$ ./doit
VARIABLE=content: Command not found.
ws$
Michael Steele_2
Honored Contributor

Re: Korn Shell Programming on hp-ux 11i

#!/usr/bin/ksh (* Use commands from this command set *)
.
.
.

#!/usr/bin/sh (* Now use this command set *)
.
.
.
.
#!/usr/bin/csh (* Now use this command set *)

All you're doing is redirecting the lines in the script to a different command set. First korn, then Posix and then C shell. And you invoke a korn shell command that doesn't appear in the C shell command set after redirecting to C shell, then it will fail to execute.

There are no wasted resources by redirecting to another command set, or shell.
Support Fatherhood - Stop Family Law
Michael Steele_2
Honored Contributor

Re: Korn Shell Programming on hp-ux 11i

#!/usr/bin/ksh (* Use commands from this command set *)
.
.
.

#!/usr/bin/sh (* Now use this command set *)
.
.
.
.
#!/usr/bin/csh (* Now use this command set *)

All you're doing is redirecting the lines in the script to a different command set. First korn, then Posix and then C shell. If you invoke a korn shell command that doesn't appear in the C shell command set after redirecting to C shell, then it will fail to execute.

There are no wasted resources by redirecting to another command set, or shell.
Support Fatherhood - Stop Family Law