Revision 3773
Added by Aaron Marcuse-Kubitza over 12 years ago
expand_braces | ||
---|---|---|
14 | 14 |
singleQuoteEsc="'\''" |
15 | 15 |
CR=$'\r' |
16 | 16 |
LF=$'\n' |
17 |
braceKeep='./{' |
|
18 |
bracketKeep='{*[*,*]*}' |
|
17 | 19 |
|
18 | 20 |
while true; do |
19 | 21 |
read # get next line from stdin; strips trailing newlines |
20 | 22 |
line="$REPLY" |
21 | 23 |
test -z "$line" && break # EOF if no line or empty line |
22 | 24 |
|
23 |
line="${line//$CR/}" # remove \r |
|
24 |
line="${line//$singleQuote/$singleQuoteEsc}" # escape single quotes |
|
25 |
# Escape non-brace chars; don't expand ./{ |
|
26 |
line="$(echo "$line"\ |
|
27 |
|sed -e "s/[^{,}]+/'&'/g"|sed -e "s/\.\/'\{'([^}]*)'\}'/.\/{\1}/g")" |
|
28 |
|
|
29 |
eval echoEach $line # brace-expand $line |
|
25 |
if test "${line/$braceKeep/}" != "$line" \ |
|
26 |
-o "${line/$bracketKeep/}" != "$line"; then # line contains unparseable exprs |
|
27 |
echo "$line" # don't expand |
|
28 |
else |
|
29 |
line="${line//$CR/}" # remove \r |
|
30 |
line="${line//$singleQuote/$singleQuoteEsc}" # escape single quotes |
|
31 |
line="$(echo "$line"|sed -e "s/[^{,}]+/'&'/g")" # escape non-brace chars |
|
32 |
|
|
33 |
eval echoEach $line # brace-expand $line |
|
34 |
fi |
|
30 | 35 |
done |
Also available in: Unified diff
expand_braces: Fixed bug where ./{ and brackets with commas inside {} are unparseable, and should not be expanded