Solved

is it valid to set the not in the first line of a script with #!

Posted on 2012-12-28
4
389 Views
Last Modified: 2013-01-09
I am a very important and  yet again mixed envirment.  

each machine has one of "bash or ksh"

If there is bash I want to use it, otherwise I can use ksh.   I never ever want to use "sh" because there are lines in my scripts  that will not run with an oversimplistic shell

Here is my solution and I need to know if people forsee a a problem with selecting your shell after the script starts.



 
## set environment so you never get /bin/sh !!!
if [[ -e "/bin/bash" ]];  then
                SHELL="/bin/bash"
                else
                                SHELL="/bin/ksh"
fi
 
echo $SHELL


Oh, I am in a redhat, solaris, aix envirement with either bash OR  ksh
0
Comment
Question by:TIMFOX123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 38727758
The SHELL variable doesn't have any influence on which interpreter is used for the script.
It's a variable like any other one, and the shell itself never evaluates it.

Best use the code you posted as a wrapper to start your script:

if [[ -e "/bin/bash" ]];  then
                /bin/bash "$@"
                else
                                /bin/ksh "$@"
fi


Call this script e.g. "launch"

and run

launch /path/to/script param1 param2 param3 paramn

Please don't use a shebang line "#!/bin/bash" or "#!/bin/ksh" in the called scripts with the above solution.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 38727971
Please see your other question on this topic for an "inline" solution!
0
 
LVL 48

Expert Comment

by:Tintin
ID: 38728097
What user will be invoking the script?

If their login shell is either bash or ksh depending on the environment, then simply omit the #! line on the script/s and it will run under the shell of the user that is running the script.
0
 

Author Closing Comment

by:TIMFOX123
ID: 38761021
Sorry for me taking so long to get back.  I work all the time and rarely get out to the "real internet "

thanks porky
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question