1

i got this snippet from a shell script , it run perfectly in Solaris environment

grep -h '??.*??' $1/{CT,{MYDIR{85,97}}{,_E}}/R*txt

but when i try to run shell script in ubuntu , it gives following error

grep: ./{MYDIR85}/R*txt: No such file or directory
grep: ./{MYDIR85}_E/R*txt: No such file or directory

after little bit of editing it run properly, i removed curly braces of MYDIR

grep -h '??.*??' $1/{CT,MYDIR{85,97} {,_E}}  /R*txt

I want to know what is the problem , is it command incompatibility between linux and solaris ?

Note -i have three directory MYDIR85 , MYDIR97 and CT - in ubuntu , shell is /bin/bash - in solaris i don't know the shell type,but the first line of shell script is #!/bin/bash

8

1 Answer 1

3

According to the bash manpages

A correctly-formed brace expansion must contain unquoted opening and closing braces, and at least one unquoted comma or a valid sequence expression. Any incorrectly formed brace expansion is left unchanged.

In your expression {MYDIR{85,97}}, the outer brace has neither an unquoted comma nor a sequence expression, so is left unexpanded - resulting in {MYDIR85} {MYDIR97}. Just for the sake of illustration, you can get the desired behavior by adding a trailing comma:

bash $ echo {MYDIR{85,97},}
MYDIR85 MYDIR97

although this would introduce an extra - presumably unwanted - _E element into your compounded expression {CT,{MYDIR{85,97}}{,_E}}.


I don't know why you're seeing different behavior under Solaris, except to note that csh does remove the outer braces under this condition (although it also accepts the trailing comma form - as do ksh and zsh apparently):

csh % echo {MYDIR{85,97}}
MYDIR85 MYDIR97
csh % echo {MYDIR{85,97},}
MYDIR85 MYDIR97

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .