OVH Cloud OVH Cloud

Expansion de variable en bash

11 réponses
Avatar
Arnaud Launay
Hop,

J'ai un petit soucis en bash:

for subdir in imap/{,db,log} ; do
mkdir $subdir
done

marche impec, mais:

SUB="imap/{,db,log}"
for subdir in ${SUB}; do
mkdir $subdir
done

Me crée un répertoire "{,db,log}" ....

Visiblement, je rate quelque chose, mais quoi ?!?

Arnaud.
--
Perso: http://launay.org/blog/
Consulting: http://www.cusae.com/
Hébergement: http://www.nocworld.com/

1 réponse

1 2
Avatar
Stephane Chazelas
2005-10-22, 10:39(+00), Arnaud Launay:
[...]
J'ai un petit soucis en bash:

for subdir in imap/{,db,log} ; do
mkdir $subdir
done

marche impec, mais:

SUB="imap/{,db,log}"
for subdir in ${SUB}; do
mkdir $subdir
done

Me crée un répertoire "{,db,log}" ....

Visiblement, je rate quelque chose, mais quoi ?!?
[...]


SUB=(imap/{,db,log})
for subdir in "${SUB[@]}"; do
mkdir -- "$subdir"
done

SUB="..."
ca cree une variable scalaire, pas une liste.

--
Stéphane

1 2