I have been searching for half an hour in vain!
This looks simple enough:
#!/bin/bash
#test.sh
echo "$0 $@">>my.log
Run command:
test.sh -a -b 'abc -c 123'
test.sh -a -b "abc -c 123"
Output:
cat my.log
test.sh -a -b abc -c 123
test.sh -a -b abc -c 123
Expected output:
cat my.log
test.sh -a -b 'abc -c 123'
test.sh -a -b "abc -c 123"
Notice the single quote in the expected output.
How do I get the expected output, do I have to manually put the quotes in?
The intention is that: I want to keep a log of how a script is invoked for later tracing back how I did my work. So the log lines must keep PRECISELY how the command was invoked and I can copy-paste and run it again.
After many searches and trials, all tricks with quotes escaping, and printf don't work. Like Others mentioned, this seems to be an built-in behavior of Bash in parse arguments that it strip off quotes. I am just wondering if it is somehow possible to pick the line from bash history
, which records precisely how commands are invoked.