Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to set the shell to bash if there is bash otherwise set to ksh

Posted on 2012-12-28
5
Medium Priority
?
579 Views
Last Modified: 2013-01-09
I am in linux , aix , solaris

Usually there is bash on the box, sometimes not
if there is bash on the box, I want to run my scripts in bash.
if there is not bash on the box THERE WILL BE KSH and i would like to set my scripts to run
in ksh ( so it does not default to sh )

how can I do this ?
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
5 Comments
 
LVL 22

Expert Comment

by:mcsween
ID: 38727564
You can set your default shell per user in /etc/passwd.  Just change the last option on the line from /bin/sh to /bin/bash or /bin/ksh

This link explains the /etc/passwd layout
http://www.cyberciti.biz/faq/understanding-etcpasswd-file-format/
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 38727672
Omit the shebang line #!...

and call your script like

[[ -x /bin/bash ]] && INTP=/bin/bash || INTP=/bin/ksh; $INTP /path/to/script

If your default login shell is either bash or ksh then you can do

$SHELL /path/to/script

Here too you must omit #!...
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 38727938
This is another trick.

Prefix your script (again without the shebang) with the following code (I took the first part from your other question):

function shellselect {
if [[ -e "/bin/bash" ]];  then
                INTERP="/bin/bash"
                else
                                INTERP="/bin/ksh"
fi; }

if [[ $1 != "12345selected54321" ]];  then
   shellselect
   $INTERP $0 "12345selected54321" "$@"
   exit
   else shift
fi
# actual code starts here, next two lines just for demonstration ...
echo $BASH # line will be empty if ksh is used, else it will contain the path to bash.
echo $@ # to show that the params are still there
# ....
# ....
0
 
LVL 48

Accepted Solution

by:
Tintin earned 2000 total points
ID: 38728085
Do the servers that have bash also have ksh?

If so, then just add

#!/bin/ksh

to your scripts
0
 

Author Closing Comment

by:TIMFOX123
ID: 38761025
Thank you so much everybody but Tintin just hit this one 100%

thx Tintin
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

705 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