LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 10-28-2004, 11:56 PM   #1
bendeco13
Member
 
Registered: Oct 2004
Distribution: Fedora 7
Posts: 232

Rep: Reputation: 30
Question exec bash command


I'm trying to use the "exec" command in my script, when the program is executed, the script stops. Is there a way to get it to keep going?
Here's my sample:
Code:
exec testprogram
cp -f "/etc/test/Default.txt~" "/etc/test/Default.txt"
rm -f "/etc/test/Default.txt~"
echo "removed"

Last edited by bendeco13; 10-28-2004 at 11:57 PM.
 
Old 10-29-2004, 01:44 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Squeeze
Posts: 5,770

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
The exec shell builtin replaces the current process with a specified command. Normally, when the shell encounters a command, it forks off a child process to actually execute the command. Using the exec builtin, the shell does not fork, and the command exec'ed replaces the shell. When used in a script, therefore, it forces an exit from the script when the exec'ed command terminates. For this reason, if an exec appears in a script, it would probably be the final command, and the last lines of your script would never run.

To work around this limitation, try putting the exec command by itself in another executable script, and call that script instead of using the exec command. When the other script finishes, the exit from that script might return execution to the script that called it.

Just guessing, but it's worth a try.

Last edited by bigrigdriver; 10-29-2004 at 01:45 AM.
 
Old 10-29-2004, 01:59 AM   #3
bendeco13
Member
 
Registered: Oct 2004
Distribution: Fedora 7
Posts: 232

Original Poster
Rep: Reputation: 30
Awesome.....That Works
THANKS ALOT
 
Old 10-29-2004, 04:11 AM   #4
kees-jan
Member
 
Registered: Sep 2004
Distribution: Debian, Ubuntu, BeatrIX, OpenWRT
Posts: 273

Rep: Reputation: 30
Uh...
I might be missing something here, but instead of creating this other script, I'd call the executable directly, i.e. without exec, like so

Code:
testprogram
cp -f "/etc/test/Default.txt~" "/etc/test/Default.txt"
rm -f "/etc/test/Default.txt~"
echo "removed"
Groetjes,

Kees-Jan
 
Old 10-30-2004, 03:39 AM   #5
bendeco13
Member
 
Registered: Oct 2004
Distribution: Fedora 7
Posts: 232

Original Poster
Rep: Reputation: 30
Thanks kees-jan, but that did the same thing...
Thanks anyways
 
Old 10-30-2004, 09:58 AM   #6
kees-jan
Member
 
Registered: Sep 2004
Distribution: Debian, Ubuntu, BeatrIX, OpenWRT
Posts: 273

Rep: Reputation: 30
Well, yes, of course. That's what you wanted it to do.

But it saves you the trouble of writing an additional script

Groetjes,

Kees-Jan
 
Old 10-31-2004, 03:50 PM   #7
bendeco13
Member
 
Registered: Oct 2004
Distribution: Fedora 7
Posts: 232

Original Poster
Rep: Reputation: 30
Yes it did work.. Kees-jan...
sorry I overlooked the idea that it's calling on bash and not using the exec command....
The script wasn't in my /usr/bin or /usr/local/bin folder....etc...etc... so I used this instead:
Code:
bash /dir/to/scipt/testprogram
cp -f "/etc/test/Default.txt~" "/etc/test/Default.txt"
rm -f "/etc/test/Default.txt~"
echo "removed"
Sorry again about that comment I left about it being the same...
Because it clearly isn't the same as using the exec command...
Thanks again Kees-jan...
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
redhat 9.0 how to use the command 'find' with the action -exec arvin_shu Linux - Newbie 3 11-30-2005 07:09 AM
exec bash scripts from Glade/GTK? HELP! cho Programming 1 07-04-2005 08:01 AM
monitor mail box and exec command brumela Linux - General 2 05-30-2005 08:13 AM
php: output the result of exec( $command ) zovres Programming 6 08-27-2004 06:41 PM
Kylix (delphi) missing exec command? RayJ Programming 2 09-24-2003 12:35 AM


All times are GMT -5. The time now is 07:18 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration