[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
brace expansion and variable expansion
From: |
Gregory Seidman |
Subject: |
brace expansion and variable expansion |
Date: |
Sat, 20 Mar 2004 15:31:22 -0500 |
User-agent: |
Mutt/1.5.4i |
Brace expansion does not occur after variable expansion. I ran across
this when writing a script that needed to cat and sort a variable subset
of files, all of which reside in some directory. Consider this example:
#!/bin/bash
SELFILES="foo"
if test $# -gt 0
then
SELFILES="$SELFILES,bar"
else
SELFILES="$SELFILES,baz"
fi
cat /tmp/stuff/{$SELFILES} | sort > /tmp/stuff/foobarbaz
Instead of the expected results, which is that cat will be given two
file paths on its commandline, cat will be given a single argument of
either /tmp/stuff/{foo,bar} or /tmp/stuff/{foo,baz}. I've tested this on
version 2.05b on both MacOS X and Debian Linux (both x86 and PPC).
I am not subscribed to the bug-bash list, so any email intended for me
should be sent directly to me (as well as the list, if appropriate).
--Greg
- brace expansion and variable expansion,
Gregory Seidman <=