Citant en arguments de la fonction d'erreur
Question
Comment devrait être fixé variable command
pour obtenir un comportement correct?
#!/bin/bash
function f ( )
{
echo "$2"
}
command="f --option=\"One Two Three\" --another_option=\"Four Five Six\""
$command
f --option="One Two Three" --another_option="Four Five Six"
Tout d'abord appel est erroné, deuxième - droit
$> ./test.sh
Two
--another_option=Four Five Six
La solution
TL; DR:. Utiliser un tableau
command=(f --option="One Two Three" --another_option="Four Five Six")
"${command[@]}"
Autres conseils
Vous ne pouvez pas fixer la variable. Mais vous pouvez:
eval $command
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow