LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 12-28-2004, 02:11 PM   #1
dfloer
LQ Newbie
 
Registered: Nov 2004
Posts: 4

Rep: Reputation: 0
bash subshells have trouble with && or || on next line


I have a problem with bash/sh scripts that use subshells. Two sample shell scripts below, both with nested subshells, the first works and the second doesn't. The difference is that the logical 'and' (&&) is on the end of line one in the first but on the beginning of line two in the second faulty script. There is no whitespace after the '\' delimiter. The scripts execute just fine on a Solaris 2.8 box. Platform is RH ES 3.0 2.4.21-20.0.1, bash version is GNU bash, version 2.05b.0(1)-release (i386-redhat-linux-gnu). Is this a bug or expected behaviour? Any advice anyone out there can offer would be appreciated. Thx.

# cat /tmp/test1
((echo line1) && \
(echo line2))
# head -1 /tmp/test1 | od -c
0000000 ( ( e c h o l i n e 1 ) & &
0000020 \ \n
0000023
#
# cat /tmp/test2
((echo line1) \
&& (echo line2))
# head -1 /tmp/test2 | od -c
0000000 ( ( e c h o l i n e 1 ) \ \n
0000020
#
# bash /tmp/test1
line1
line2
#
# bash /tmp/test2
/tmp/test2: line 2: syntax error near unexpected token `'
/tmp/test2: line 2: `&& (echo line2))'
 
Old 12-28-2004, 02:58 PM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
How about not using the \ at the end....

((echo line1)
&& (echo line2))
 
Old 12-28-2004, 03:05 PM   #3
dfloer
LQ Newbie
 
Registered: Nov 2004
Posts: 4

Original Poster
Rep: Reputation: 0
Same result. Still fails when '\' is removed from /tmp/test2:

# cat /tmp/test2
((echo line1)
&& (echo line2))
# sh /tmp/test2
/tmp/test2: line 2: syntax error near unexpected token `&&'
/tmp/test2: line 2: `&& (echo line2))'
 
Old 12-28-2004, 03:22 PM   #4
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
Take a look at the parentheses: one unmatch open paren on the first line; one unmatched closes paren on the second. Try removing the unmatched paren from each line.
 
Old 12-28-2004, 03:25 PM   #5
dfloer
LQ Newbie
 
Registered: Nov 2004
Posts: 4

Original Poster
Rep: Reputation: 0
There are easier fixes than removing the unmatched parens. But I'm not after a fix, I'm trying to confirm if this is expected behaviour or a bug. IMHO, the '\' should tell bash the next line is a continuation of the previous line, so bash shouldn't report unmatched parens error. This is how it behaves under Solaris. The issue is not to find a workaround, we have lots. The question is whether or not this is a bug that the Linux community and Red Hat should fix or is it expected behaviour.
 
Old 12-28-2004, 03:27 PM   #6
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
//

Last edited by homey; 12-28-2004 at 04:05 PM.
 
Old 12-28-2004, 03:50 PM   #7
dfloer
LQ Newbie
 
Registered: Nov 2004
Posts: 4

Original Poster
Rep: Reputation: 0
That's not the problem. The problem arises when running within a script. You essentially eliminated the problem by putting both subshells on the same line, which is not what we're after. I have all the fixes we need. We need to know if this should be fixed in bash. Need some high-level shell gurus to step in here.
 
  


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 redirection and subshells nx5000 Programming 2 11-03-2005 06:13 AM
Bash scripting and && operator Dark_Helmet Programming 16 09-18-2005 09:57 PM
Japanese canna won't work : Warning: かな漢字変&am OrganicOrange84 Debian 3 06-30-2005 02:28 PM
Phục hồi dữ liệu bị mất???, cứ pollsite General 1 06-27-2005 12:39 PM
trouble with apache 1.3 & https & debian deuce868 Linux - Networking 0 11-20-2004 08:11 PM

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

All times are GMT -5. The time now is 04:38 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