LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-17-2010, 08:54 AM   #1
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,183
Blog Entries: 21

Rep: Reputation: 151Reputation: 151
bash "exec" command won't


The "exec" command in bash is supposed to replace the current process with the command being executed. On my slightly older Slackware 12.0 system, it does just that in my bash scripts, even in pipelines. However, in a newer Ubuntu 9.10 system, it fails to. When the command line with an exec command is done, bash proceeds to execute the next command. Lots of scripts expect "exec" to not proceed to the next command. Is bash now broken or did Ubuntu goof it up?
 
Old 03-17-2010, 09:25 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
Bizarre! Maybe exec is an alias; try builtin exec. Incidentally, it's not a bad idea to start scripts with unalias -a so you know what's what.
 
Old 03-17-2010, 02:30 PM   #3
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,183

Original Poster
Blog Entries: 21

Rep: Reputation: 151Reputation: 151
It looks like it's related to using the command in a pipeline. But I know I've done that successfully in the past in pipelines. It just doesn't do it now. I'm going to have to hunt down old scripts, now. But I just tried a test case script on Slackware and Debian and it fails the same way there, too.

Code:
#!/bin/bash
unalias -a
echo 0
df /home | exec cat
echo 1
exec df /home | cat
echo 2
df /home | builtin exec cat
echo 3
builtin exec df /home | cat
echo 4
exec df /home
echo 5
exit 1
 
Old 03-17-2010, 03:43 PM   #4
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,953

Rep: Reputation: 691Reputation: 691Reputation: 691Reputation: 691Reputation: 691Reputation: 691
Hi,
look here:
http://mywiki.wooledge.org/BashPitfa....29.29.3B_done
http://mywiki.wooledge.org/SubShell
It appears that EVERY command in a pipeline is executed in a subshell, unless you use ksh88 and ksh93. There the last command is run in the current shell.
Hope this helps.
 
Old 03-17-2010, 04:08 PM   #5
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,183

Original Poster
Blog Entries: 21

Rep: Reputation: 151Reputation: 151
I wonder when they broke it. It used to work. But thinking on it, that was many years ago. Could be anywhere between then and now.

I started learning Python this year to do some programming. I guess it will be my new scripting language, too.
 
  


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
please help with bash find / -name "*.sized.jpg" -exec rm -f {} ; rioguia Programming 4 01-16-2010 04:48 PM
MUTT keeps telling me Bad login on "exec fetch-mail" command aliasX Linux - Server 0 05-17-2009 01:04 PM
fail to start xterm: "could not exec /usr/OSE/bash: No such file or directory" freeindy Linux - General 3 11-28-2008 01:22 AM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 11:18 PM
does "find -exec" not recognize built-in command? yaru22 Linux - General 1 06-30-2006 11:35 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:15 AM.

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