?
Solved

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

Posted on 2012-12-28
4
Medium Priority
?
390 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 2000 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

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

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

The purpose of this article is to demonstrate how we can use conditional statements using Python.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
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ā€¦
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month9 days, 23 hours left to enroll

762 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