Thursday, 22 August 2013

Is it possible to preserve quotations by storing $@ into another variable?

Is it possible to preserve quotations by storing $@ into another variable?

If I have this on the command line:
bin/my_file --name "this name with whitespace" dir/some_file
Then in my script:
full_cmd="$@"
# later...
"$full_cmd"
The quotation marks are not preserved. This is the closest I've come:
app=$1
shift
$app "$@"
However, it would be convenient if it were possible to save the "$@" into
a variable to re-use later, like this:
my_func () {
$app "$args"
}
I haven't been able to make any of that work... other than messy for
loops. I'm new to bash. I've search all other possible solutions and can't
figure out why this is so hard. Am I missing something obvious?

No comments:

Post a Comment