Quote:
Originally Posted by mntbighker
Code:
# List torque_properties
for i in {0..$LN}
do
qmgr -c "list node compute-0-${i}"
done
What I get back is qmgr -c "list node compute-0-{0..4}".
|
This is a shell expansion issue. The
$LN variable is expanded after the brace expansion has taken place, which ruins the
for loop.
I can think of (at least) two possible solutions/workarounds. First of all, you could use a C-style
for loop instead of braces:
Code:
# List torque_properties
for (( i=0; i<=$LN; i++ ))
do
qmgr -c "list node compute-0-${i}"
done
In addition to handling variables, C-style loops can count down as well as up, and use increments/decrements other than 1. What's not to like?
Another possibility would be to use
echo and
eval to force shell expansion to occur in the required order (really, really ugly):
Code:
# List torque_properties
eval `echo for i in {0..$LN}\; do qmgr -c "list node compute-0-\${i}"\; done`
Here, the
echo statement expands
$LN while the loop variable (and the semicolons) are preserved by means of escaping. The result is then fed to
eval, which will execute the entire statement.
Now, I see no reason why any sane person would choose the latter approach in this particular case, but I've included it to show how
echo and
eval could be used if one really needs to force expansion to happen in a particular, non-standard order.