[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
command substition with $(cmd) parenthesis match
From: |
th |
Subject: |
command substition with $(cmd) parenthesis match |
Date: |
Mon, 3 Mar 2003 14:00:30 +0100 (CET) |
Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i686'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu'
-DCONF_VENDOR='pc' -DSHELL -DHAVE_CONFIG_H -D_FILE_OFFSET_BITS=64 -I. -I.
-I./include -I./lib -I/sw/i386_lnx2/bash-2.04/include -g -O2
uname output: Linux redhat7.LF.net 2.4.9-31 #1 Tue Feb 26 06:53:37 EST 2002
i686 unknown
Machine Type: i686-pc-linux-gnu
Bash Version: 2.04
Patch Level: 0
Release Status: release
Description:
-----
#!/bin/bash
res=$( case "$1" in
"test")
# do something
echo "test";;
*)
# do something
echo "other";;
esac | wc -c
)
echo $res
-----
Trying to execute the given code will result in the message:
test.sh: command substitution: line 2: syntax error near unexpected
token `"test"'
test.sh: command substitution: line 2: ` "test"'
test.sh: line 6: syntax error near unexpected token `;'
test.sh: line 6: ` echo "test";;'
The same code works on FreeBSDs /bin/sh.
After changing $( ... ) into backticks the script works as expected:
-----
#!/bin/bash
res=` case "$1" in
"test")
# do something
echo "test";;
*)
# do something
echo "other";;
esac | wc -c
`
echo $res
-----
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- command substition with $(cmd) parenthesis match,
th <=