- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: how to change shell within the script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2009 02:24 PM
тАО08-26-2009 02:24 PM
how to change shell within the script
I just want shell changed for this session only. How can I change my sheel from ksh to bsh within the script?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2009 02:31 PM
тАО08-26-2009 02:31 PM
Re: how to change shell within the script
> How can I change my sheel from ksh to bsh within the script?
You don't have to if your script begins with a "she-bang" interpreter line. In HP-uX:
#!/bin/sh
...is equivalent to:
#!/usr/bin/sh
...which is the POSIX shell --- the HP-UX standard. You login shell (as defined in '/etc/passwd') might be the Korn shell ('/usr/bin/ksh') but your script will run as the POSIX shell when your interpreter line reads:
#!/usr/bin/sh
(or)
#/bin/sh
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2009 02:35 PM
тАО08-26-2009 02:35 PM
Re: how to change shell within the script
I don't know what that means. If the script
starts with "#!/bin/sh", then that's what
gets run to interpret the script.
> So in the script, I say echo $SHELL after
> /bin/shell line and shell is ksh.
If that bothers you, then you could set SHELL
to some other value (in your script). I
don't know how that will help you, but you
can do it.
Is there some actual problem which you are
trying to solve?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2009 08:00 PM
тАО08-26-2009 08:00 PM
Re: how to change shell within the script
#!/usr/bin/sh
#!/usr/bin/ksh
#!/usr/bin/awk
#!/usr/local/bin/bash
and so on. A script is a set of instructions that are designed to be run by a specific program. Whether the program is also your shell or some other program is not important. If you do not have the #! line in your script, then you script will be run by the current shell -- not a good idea at all. Always specify the #! line for every script.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2009 08:44 PM
тАО08-26-2009 08:44 PM
Re: how to change shell within the script
> If you do not have the #! line [...]
Make up your mind. (Or else don't say "must"
when you really mean "should".)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-27-2009 12:03 AM
тАО08-27-2009 12:03 AM
Re: how to change shell within the script
SHELL is set by login(1). And just about the only program that looks at $SHELL is make.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-27-2009 01:12 AM
тАО08-27-2009 01:12 AM
Re: how to change shell within the script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-27-2009 03:47 AM
тАО08-27-2009 03:47 AM
Re: how to change shell within the script
> bsh is posix shell
Yes, it has Posix compliance. BUT: In HP-UX, the standard shell in '/usr/bin/sh' and in '/sbin/sh' is called the "Posix" shell. The important part is that while the 'bash' or the 'ksh' or other shell may be declared as a user's default shell, you should NEVER change root's default login shell. For root, only the statically linked '/sbin/sh' will allow you to reboot and startup a system (when '/usr' and the dynamic libraries every other shell needs) isn't mounted.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-27-2009 04:12 AM
тАО08-27-2009 04:12 AM
Re: how to change shell within the script
There's a little trick you can use to get the shell to use a PATH search to find the Perl interpreter for you:
----
:
eval 'exec perl -S $0 ${1+"$@"}'
if $running_under_some_shell;
print "Hello world!\n";
----
I use this when some systems have Perl in /usr/local/bin and others have it in /usr/bin, when I haven't gotten around to symlinking.
The colon sends the script to sh, which runs the "eval/exec" line to fire up Perl on the same file, and then Perl ignores that line because "$running_under_some_shell" on the following line is not set, and proceeds down to the rest of the Perl script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-27-2009 04:24 AM
тАО08-27-2009 04:24 AM
Re: how to change shell within the script
> mvpel: Actually, Bill, not every script must start with #!. There's a little trick you can use to get the shell to use a PATH search to find the Perl interpreter for you:
A less obtuse way is simply:
#!/usr/bin/env perl
(or):
#!/usr/bin/env ksh
In which case we could still say that "every script must start with #!" :-)
Regards!
...JRF...