Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
share|improve this question
Also appears in stackoverflow – glenn jackman Sep 9 '11 at 13:00
up vote 7 down vote accepted

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")
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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