Bash prints syntax error when command in $(...) contains case-esac

2008-09-30 Thread Juergen Gohlke

Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: cygwin
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash.exe' -DCONF_HOSTTYPE='i686' 
-DCONF_OSTYPE='cygwin' -DCONF_MACHTYPE='i686-pc-cygwin' 
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' 
-DSHELL -DHAVE_CONFIG_H -DRECYCLES_PIDS   -I.  
-I/home/eblake/bash-3.2.9-11/src/bash-3.2 
-I/home/eblake/bash-3.2.9-11/src/bash-3.2/include 
-I/home/eblake/bash-3.2.9-11/src/bash-3.2/lib   -O2 -pipe
uname output: CYGWIN_NT-5.0 JONA 1.5.24(0.156/4/2) 2007-01-31 10:57 i686 
Cygwin

Machine Type: i686-pc-cygwin

Bash Version: 3.2
Patch Level: 9
Release Status: release

Description:
   If a command in $(...) contains a case-esac construction, the 
bash prints a syntax error instead

   of executing the code:
   bash: syntax error near unexpected token `;;'

Repeat-By:
   A simple example is: x=$(a=4; case $a in 3) echo a=3;; 4) echo 
a=4;; esac)

   (typed in an interactive shell or being part of a shell script).
   The same error has been seen on Windows Vista, Windows XP and 
Windows2000.
   The same error has been seen with an earlier version of bash, 
i.e. 2.05b.0(8)-release

   If $(...) is replaced by `...`, it works.



Re: Bash prints syntax error when command in $(...) contains case-esac

2008-09-30 Thread Bernd Eggink

Juergen Gohlke schrieb:

Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: cygwin
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash.exe' -DCONF_HOSTTYPE='i686' 
-DCONF_OSTYPE='cygwin' -DCONF_MACHTYPE='i686-pc-cygwin' 
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' 
-DSHELL -DHAVE_CONFIG_H -DRECYCLES_PIDS   -I.  
-I/home/eblake/bash-3.2.9-11/src/bash-3.2 
-I/home/eblake/bash-3.2.9-11/src/bash-3.2/include 
-I/home/eblake/bash-3.2.9-11/src/bash-3.2/lib   -O2 -pipe
uname output: CYGWIN_NT-5.0 JONA 1.5.24(0.156/4/2) 2007-01-31 10:57 i686 
Cygwin

Machine Type: i686-pc-cygwin

Bash Version: 3.2
Patch Level: 9
Release Status: release

Description:
   If a command in $(...) contains a case-esac construction, the 
bash prints a syntax error instead

   of executing the code:
   bash: syntax error near unexpected token `;;'

Repeat-By:
   A simple example is: x=$(a=4; case $a in 3) echo a=3;; 4) echo 
a=4;; esac)

   (typed in an interactive shell or being part of a shell script).
   The same error has been seen on Windows Vista, Windows XP and 
Windows2000.
   The same error has been seen with an earlier version of bash, 
i.e. 2.05b.0(8)-release

   If $(...) is replaced by `...`, it works.


The problem is caused by the semi-parenthesized case labels 3) and 4). 
Bash matches the first unpaired right paren (after the 3) with the last 
unpaired left paren (in $( ). Using (3) and (4) instead makes the 
example work.

Unpaired parens are hideous anyway, IMHO.

Regards,
Bernd

--
Bernd Eggink
[EMAIL PROTECTED]
http://sudrala.de




Re: Graceful Exit

2008-09-30 Thread Roman Rakus

rayparrish wrote:

Hello,

I am writing a System Report script for Ubuntu, and even 'though I have the
word exit on the last line of the script, when I run the script in terminal
I have to hit enter a second time after running the script to get the
terminal prompt back.

I'm uploading the script, have a look and tell me how to get this thing to
exit back to the terminal prompt without the second enter key press.

Thanks, Ray Parrish

http://www.nabble.com/file/p19598628/SystemReport.sh SystemReport.sh 


Hello again,

I did some debugging and found that my script was choking on the line -

cat | df -h  ~/SysReport/drive.html

I removed the cat | from the front of the command and now my script runs
through and exits no problem.

 Thanks,. Ray Parrish
  

of course, cat was reading from stdin, but has no input from stdin.
And I have take a look at script and found that you have at some lines 
windows style end of lines. Maybe better you should fix it.

RR




Re: Bash prints syntax error when command in $(...) contains case-esac

2008-09-30 Thread Jan Schampera

Juergen Gohlke wrote:


Description:
   If a command in $(...) contains a case-esac construction, the 
bash prints a syntax error instead

   of executing the code:
   bash: syntax error near unexpected token `;;'


In case you have trouble with code you need, use this workaround:

x=$(a=4; case $a in (3) echo a=3;; (4) echo a=4;; esac)

And yes, I've also seen this before and I thought it was fixed - maybe I 
thought of something else.


J.




Re: Bash prints syntax error when command in $(...) contains case-esac

2008-09-30 Thread Chet Ramey
 Machine Type: i686-pc-cygwin
 
 Bash Version: 3.2
 Patch Level: 9
 Release Status: release
 
 Description:
 If a command in $(...) contains a case-esac construction, the 
 bash prints a syntax error instead
 of executing the code:
 bash: syntax error near unexpected token `;;'
 
 Repeat-By:
 A simple example is: x=$(a=4; case $a in 3) echo a=3;; 4) echo a=4;; 
 esac)

This is a long-standing problem, caused by the bash parser's
requirement that parens match.  Posix introduced the optional left
paren before a case statement pattern list to finesse the problem, but
current versions of the standard require that commands inside $(...)
be parsed correctly even in the absence of balanced parens.  Bash-4.0
will work as you expect, without requiring the parens to balance. 

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer

Chet Ramey, ITS, CWRU[EMAIL PROTECTED]http://tiswww.tis.case.edu/~chet/




Terminated message from kill

2008-09-30 Thread Glenn Morris

Hi,

This is a question similar to one from September 2006:

http://lists.gnu.org/archive/html/bug-bash/2006-09/msg00077.html


Using bash 3.2.39 on x86_64 RHEL5.2, I have a script with contents:


function bar ()
{
sleep 10 
pid=$!
exec 32 2/dev/null
kill $pid
#usleep 1
exec 23 3-
}

bar


If I run this script 1000 times via a loop, I get a handful of messages
(the number varies) of the form:

/path/to/script: line 14: 10327 Terminated  sleep 10

If I uncomment the usleep line, I get no such messages at all.

If I comment out the usleep and both exec lines, I get a handful of messages.

If I then uncomment the usleep line, I get 1000 messages.


Hence, some questions:

1) Shouldn't the production of the terminated message be deterministic?

2) Why does sleeping make a difference?

3) Is there a right way to suppress the terminated message?

Thanks in advance.