LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-04-2007, 12:01 AM   #1
jaykup
Member
 
Registered: Jan 2006
Location: Mukwonago, WI
Distribution: Slackware 12
Posts: 77

Rep: Reputation: 16
Changing Shells in a script


Is it possible to change from one shell or program to another in the same script file?

example:

Code:
#!/bin/bash
echo "this is a bash command"

#!/usr/bin/wish
button .my_button -text "Button Text" -command exit 
pack .my_button
would be one file. shebang is the only way I know to specify the interpreter / program.
 
Old 05-04-2007, 01:15 AM   #2
Micro420
Senior Member
 
Registered: Aug 2003
Location: Berkeley, CA
Distribution: Mac OS X Leopard 10.6.2, Windows 2003 Server/Vista/7/XP/2000/NT/98, Ubuntux64, CentOS4.8/5.4
Posts: 2,986

Rep: Reputation: 45
I have no idea, but why don't you try it and let us know. Another idea could be creating another file with a separate shell and calling on that file. For example:

#!/bin/bash
echo "hello"
/home/username/wish.sh
 
Old 05-04-2007, 07:21 AM   #3
jaykup
Member
 
Registered: Jan 2006
Location: Mukwonago, WI
Distribution: Slackware 12
Posts: 77

Original Poster
Rep: Reputation: 16
How you have it is how I did it, but I would like to have it all in one script.

When I try it, it doesn't change from bash to wish, or perl, or anything else. It only reads the first line that way.
 
Old 05-04-2007, 12:09 PM   #4
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 233Reputation: 233Reputation: 233
The "shebang" only works on the 1st line. -- Try beginning a shell script w/ a new line.

I think what you want is chsh. Never used it inside a script. The changed to shell (wish) would have to have similar command to come back.

Another way might be to just execute wish inside the bash script. Since I haven't used wish, I don't know what the implications of that would be.
 
Old 05-05-2007, 08:01 PM   #5
MasterC
LQ Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu
Posts: 12,612

Rep: Reputation: 64
How about creating 2 scripts, but using 1 to call them both?

-Chad
 
Old 05-05-2007, 08:26 PM   #6
jaykup
Member
 
Registered: Jan 2006
Location: Mukwonago, WI
Distribution: Slackware 12
Posts: 77

Original Poster
Rep: Reputation: 16
I thought of that too, but what I ended up doing is:

Code:
cat <<EOF > wish_script
#!/usr/bin/wish
code here
and here
and here
EOF
I liked this way because I could specify variables from the bash script into the wish script and output a new script each time it was ran. At the end of the script, it could delete the wish script too.
 
Old 05-06-2007, 11:19 AM   #7
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 233Reputation: 233Reputation: 233
Nice hack.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help changing backup script phatboyz Programming 4 06-11-2005 12:36 PM
changing shells - for a newbie kjs Linux - Software 1 12-04-2004 07:59 AM
changing shells laclac01 Linux - General 1 07-22-2004 09:04 AM
Changing to root from within a script bdika Linux - Software 2 01-01-2004 11:23 PM
changing user shells Syncrm Linux - General 3 02-17-2002 03:36 PM


All times are GMT -5. The time now is 07:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration