Reputation: 4830
function ctrace {
echo "+ $@"
"$@"
}
ctrace echo "hi"
How would I get this function to output (with quotes):
echo "hi"
In this version the quotes are lost echo hi
... Here is another example:
a=b
ctrace echo $a
This should output echo $a
instead of echo b
Upvotes: 0
Views: 213
Reputation: 49473
You need to enclose the string within single quotes
ctrace 'echo "hi"'
ctrace 'echo $a'
Upvotes: 0
Reputation: 44354
The problem is not the function, but the caller.
In the first case the quotes are stripped out before the function gets the parameters. In the second, $a
substitution is done before it gets to the function.
Try:
ctrace 'echo "hi"'
ctrace 'echo $a'
Upvotes: 1