Arguments commande sh
Fermé
bernard
-
12 déc. 2009 à 15:17
dubcek Messages postés 18783 Date d'inscription lundi 15 janvier 2007 Statut Contributeur Dernière intervention 22 avril 2025 - 13 déc. 2009 à 08:44
dubcek Messages postés 18783 Date d'inscription lundi 15 janvier 2007 Statut Contributeur Dernière intervention 22 avril 2025 - 13 déc. 2009 à 08:44
A voir également:
- Arguments commande sh
- Invite de commande - Guide
- Commande terminal mac - Guide
- Commande dism - Guide
- Commande sfc scannow - Guide
- Diskpart commande - Guide
6 réponses
jipicy
Messages postés
40842
Date d'inscription
jeudi 28 août 2003
Statut
Modérateur
Dernière intervention
10 août 2020
4 898
12 déc. 2009 à 15:39
12 déc. 2009 à 15:39
Salut,
;-))
[tmpfs]$ cat foo.sh #!/bin/bash #set -xv i=3 while [ "$i" -le "5" ] do eval echo "\$$i" ((i++)) done [tmpfs]$ ./foo.sh a b c d e f g h c d e [tmpfs]$
;-))
dubcek
Messages postés
18783
Date d'inscription
lundi 15 janvier 2007
Statut
Contributeur
Dernière intervention
22 avril 2025
5 630
12 déc. 2009 à 15:43
12 déc. 2009 à 15:43
hello
$ ./f a b c d e f g h c d e f g h $ ./f arg1 arg2 arg3 arg4 arg5 arg3 arg4 arg5 $ cat f #!/bin/bash for((arg=3; arg <= $#;arg++)) ; do echo ${!arg} ; done
dubcek
Messages postés
18783
Date d'inscription
lundi 15 janvier 2007
Statut
Contributeur
Dernière intervention
22 avril 2025
5 630
12 déc. 2009 à 15:53
12 déc. 2009 à 15:53
non, mais il y manque le test de fin, $# représente le nombre d'arguments
dubcek
Messages postés
18783
Date d'inscription
lundi 15 janvier 2007
Statut
Contributeur
Dernière intervention
22 avril 2025
5 630
12 déc. 2009 à 15:58
12 déc. 2009 à 15:58
et aussi ${!arg} pour afficher le nième argument et non pas $arg
jipicy
Messages postés
40842
Date d'inscription
jeudi 28 août 2003
Statut
Modérateur
Dernière intervention
10 août 2020
4 898
>
bernard
12 déc. 2009 à 16:01
12 déc. 2009 à 16:01
Il te l'a donné dans son exemple :
$ cat f #!/bin/bash for((arg=3; arg <= $#;arg++)) ; do echo ${!arg} ; done
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
dubcek
Messages postés
18783
Date d'inscription
lundi 15 janvier 2007
Statut
Contributeur
Dernière intervention
22 avril 2025
5 630
12 déc. 2009 à 16:02
12 déc. 2009 à 16:02
pour sortir d'une boucle for tu peux faire
if [ $i -ge $# ] ; then break ; fi
if [ $i -ge $# ] ; then break ; fi
dubcek
Messages postés
18783
Date d'inscription
lundi 15 janvier 2007
Statut
Contributeur
Dernière intervention
22 avril 2025
5 630
13 déc. 2009 à 08:44
13 déc. 2009 à 08:44
on peut aussi faire:
mais dans ce cas, $3 devient $1, donc les 2 premiers arguments ne sont plus accessibles
#!/bin/bash shift 2 for ARG in $@ ; do echo $ARG ; done
mais dans ce cas, $3 devient $1, donc les 2 premiers arguments ne sont plus accessibles
12 déc. 2009 à 15:43