How should I write the command variable to get the expected behavior?


function f ( )
    echo "$2"
command="f --option=\"One Two Three\" --another_option=\"Four Five Six\""

f --option="One Two Three" --another_option="Four Five Six"

First calling is wrong, second - right

$> ./test.sh 
--another_option=Four Five Six

BASH FAQ entry #50: "I'm trying to put a command in a variable, but the complex cases always fail!"

TL;DR: Use an array.

command=(f --option="One Two Three" --another_option="Four Five Six")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.