Command line argument

Hi Guys, I'm trying to work out how to add a command line argument inside single quotes. Would anyone be able to help please as I'm going mad :slight_smile:

I want to be able to place the filename on command line and it then be used in a script but it needs to have quotes surrounding it.

Thanks in advance.

Hi mutley,

I do not understand what you want to accomplish with this. Why do you need the quotes? You can add them inside your script if you really need it. Probably that's not the solution helping you best. Please clarify your problem/task.

Regards,
stomp

Hi Stomp,
I'm in control of a built in script which i cant modify so am having to try find a working way of being able to change the command being run. As an example below, basically i want to be able to change the 'show log' command to a command that can be entered on command line.

 Capture_log command='show log' -o file='/home/user1/1.txt

Ah. Ok. I see. You think you need to use single quotes. But single quotes does not allow Variables-expansion inside.

You can just use double quotes. Should work like you want it:

MY_COMMAND="show full log"
Capture_log command="$MY_COMMAND" -o file='/home/user1/1.txt

The quotes are only there to keep the enclosed parameter in one piece. They are not delivered within the parameter. If the quotes are missing a parameter with spaces in it would be split up at those spaces(Not what you want). Thatswhy "...." and '...' can be exchanged here. The difference between the two is explained by your example: '...' protects from variables/subprocess/... expansion. "..." however allows this.

This still is far from clear. Is the line you cited not the command line? Please give way more context.

Just guessing: Do you want to read/assign something into a shell variable and use that instead of the show log , and it must be single quoted? Try double quoting the entire single quoted variable, as single quotes lose their meaning inside double quotes:

 CMD="list file"
echo '$CMD'
$CMD
echo "'$CMD'"
'list file'