Use eval
to tell the shell to parse the command-line anew:
c="cmake . -G \"Unix Makefiles\""
eval "$c"
Alternatively, I like using arrays to avoid the unnecessary backslashes and eval
:
# Store command in 4-element array: ["cmake", ".", "-G", "Unix Makefiles"].
# No backslash escapes needed.
c=(cmake . -G "Unix Makefiles")
# Ugly syntax for expanding out each element of an array, with all the spaces and
# quoting preserved to ensure that "Unix Makefiles" remains a single word.
"${c[@]}"