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
    update to include details of shell used on solaris vs linux, e.g. echo $SHELL ? Commented Dec 26, 2016 at 15:02
  • is $1 set ? curly brace are fine in ubuntu. try setting shopt -s nullglob. Commented Dec 26, 2016 at 15:03
  • Sounds like a csh thing to me - see for example Why doesn't bash treat brace expansions exactly like csh? Commented Dec 26, 2016 at 15:08
  • @steve i updated my question Commented Dec 26, 2016 at 15:09
  • @Archemar yes i pass dot . Commented Dec 26, 2016 at 15:10

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.