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
Était-ce utile?

La solution

BASH FAQ entrée # 50: « Je suis en train de mettre une commande dans une variable, mais le complexe cas échouent toujours! "

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
scroll top