Visit Our UNIX and Linux User Community

Switching shells in UNIX Scripts

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Switching shells in UNIX Scripts
# 1  
Old 11-10-2005
Switching shells in UNIX Scripts


Newbie here to scripting in UNIX/SOLARIS.
What I am looking to do is, once the script is
executed, switch to /bin/bash shell and continue
to execute the script.

The problem I run into is once the script switches to the Bash
shell, the script stops, and does not execute the remainder of the script.

Script looks like:

/bin/bash to switch to Bash shell

Then the remaider of the script to execute

Anyone know how I can switch shells in a script and still have the script execute the lines below the switch?

# 2  
Old 11-10-2005
I doubt you can switch the shell in the middle of a script.

Why do you want to switch ?

the shells have similiar constructs save for a few ones.

Anyway, you can compile the second part of the script as a new script which runs in bash and invoke that.

#! /bin/ksh
# commands 
# which 
# runs 
# in 
# the 
# ksh 
# shell
. ./script-that-requires-bash


script-that-requires-bash is

#! /bin/bash
# commands 
# which 
# runs 
# in 
# the 
# bash
# shell

If you export any variables in the ksh script, there is a chance that the inner script might not be able to see it. It depends on the way you invoke the ksh script.
# 3  
Old 11-10-2005
Thanks for the tip.
Reason for going to Bash is because if I don't I get errors using
wildcard (*) with the gzip command...not sure why...

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Switching from production to development envirornment in UNIX

I had a unix scripts in prod. I need to made changes in those scripts which I don't have the edit access. I need to move those scripts from prod to dev to edit. Please tell me how to switch from production to development, So that I can made changes in dev and again move those scripts to Prod. ... (3 Replies)
Discussion started by: Rajeswararao
3 Replies

2. Programming

UNIX shells scripting

Can someone help by advising hw to built myself strong on logic building in UNIX shell scripting. I find it very difficult Sent from my iPhone using Tapatalk (4 Replies)
Discussion started by: Vijaykannan T
4 Replies

3. Linux

Switching between Windows and UNIX

I have both UNIX and Windows on my system. While booting it asks for me to select an OS. Once I log in to an OS, then to log in to another OS, there is no direct method. I need to shutdown and again start to select another OS. May I know any method to directly switch between the two. (23 Replies)
Discussion started by: ravisingh
23 Replies

4. UNIX for Dummies Questions & Answers

shells and scripts

So in UNIX, I understand that there are several different shells you can be in: C, Bourne, Bourne Again, Korn, etc. I also know that you can write scripts for the shells, by assigning it by #!/bin/csh, or sh, etc. If I am working in the csh, do I have to write the script for the csh? Or can it... (1 Reply)
Discussion started by: bjstaff
1 Replies

5. Shell Programming and Scripting

Switching between shells

I don't know why, but it just isn't working how I want it to work. You might want to run it to see what I mean. Or you might be a genius (or just really good at unix) and know just by looking at it what the problem is. Have fun trying to figure this one out.:wall: (11 Replies)
Discussion started by: nowruzr
11 Replies

6. Cybersecurity

Preventing switching shells

Hello, My firm has a requirement that everyone must use bash. Of course, there can be exceptions so I do not want to disable the other shells. But is there a way that I can prevent users from switching to another shell? Thank you. (5 Replies)
Discussion started by: danielf
5 Replies

7. UNIX for Dummies Questions & Answers

Unix Kernel Switching?

How do I go about switching from one Kernel to another? I figure the process is somewhat like "compile -> remove old boot reference -> add new boot reference -> reboot/restart kernel"... but honestly I have no idea how to do this... I'm trying to test out a piece of software, but it only runs... (3 Replies)
Discussion started by: jjinno
3 Replies

8. UNIX for Dummies Questions & Answers

How to open multiple shells while the scripts keeps running.

Hello, I've tried for a while now to run a bash script that continues to the end, while opening new shells as needed. I've tried xterm -e "somecommand"; & xterm -e " somecommand"; I've also tried screen -S "somecommand"; & screen -S "somecommand"; All without any luck, they... (5 Replies)
Discussion started by: Closed_Socket
5 Replies

9. UNIX for Dummies Questions & Answers

switching shells??

Hi How can i switch shells on linux and freebsd? i tried changing the passwd file and restarted the computer but i still get the same old shell. anybody has the answer? thanks (6 Replies)
Discussion started by: xNYx
6 Replies

10. UNIX for Dummies Questions & Answers

Good Unix Shells ?

Hey Guys i am new to Unix and i have downlaoded Cygwin for Windows and deleted it. I was just wondering is there any good shells like that for windows that just as good thanks for your time ][ce (1 Reply)
Discussion started by: IceCold
1 Replies

Featured Tech Videos