LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-24-2008, 03:47 AM   #1
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 598

Rep: Reputation: 30
Another one help needed on bash scripting


Hi all,

I am calling script second.sh from script one.sh.
Though I made the last line of second.sh as "exit" , all the other lines down the second.sh in first.sh is not executed.

How can I exit from second.sh and execute the remaining lines in first.sh


Cheers
 
Old 09-24-2008, 04:00 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,369

Rep: Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753
Think we'd need to see the code.

1. the exit in the called (2nd) script is redundant (you don't need it)
2. sounds like you might be including/sourcing the 2nd script instead of calling it eg

. 2nd.sh

or

source 2nd.sh

either of those syntaxes make 2nd script part of 1st script, instead of calling it externally, so the exit in the 2nd script will exit both scripts.
 
Old 09-24-2008, 04:02 AM   #3
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
How are you calling second.sh in first.sh? If you are using one of these:
Code:
. second.sh
source second.sh
... that would explain the behavior. sourcing or executing with the dot notation means "read the contents of this file and execute it in the current shell". Thus, when "exit" is called, the first (only) shell will exit.

If you're using exec, then that will also exhibit the same behaviour, because the exec command means "replace the current process with this command", and at that point, your origial script goes away, never to be returned to.

What you probably want to do is execute second.sh in a sub-shell. If you have set the permissions so the file is executable, you can just use the path to the file like this:
Code:
./second.sh          # if it's in the present working directory
/path/to/second.sh   # if you prefer to specify full path
second.sh            # if the location is somewhere in the PATH
The caveat is that a sub-process cannot modify the environment of the parent. If you need to do this you can pass output on stdout, or can source a file which defines functions, which you can then execute in the "parent" script.
 
Old 09-24-2008, 04:11 AM   #4
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 598

Original Poster
Rep: Reputation: 30
Matthew,Chrism,


Sorry to all

Please Ignore this Post. I made a mistake in my script itself .

Thanks for your efforts

Last edited by ZAMO; 09-24-2008 at 04:17 AM.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash scripting help needed ZAMO Linux - General 9 08-05-2008 08:07 AM
Bash scripting help needed ZAMO Linux - General 3 05-08-2008 09:52 AM
Bash scripting help needed ZAMO Linux - General 11 05-02-2008 06:22 AM
bash scripting help needed tine Programming 3 09-03-2007 09:13 AM
bash scripting --- some help needed rajsharma Linux - Software 1 09-09-2005 02:49 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:40 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
Open Source Consulting | Domain Registration