In a nutshell can someone explain me the difference between the various methods of quoting. I don't seem to understand when to use ' and ` or " characters. And AFAICT it _does_ make a difference.
In a nutshell can someone explain me the difference between the various methods of quoting. I don't seem to understand when to use ' and ` or " characters. And AFAICT it _does_ make a difference.
Backquotes (`) are used to store the output of a command in a variable. For example:
This will put the content of 'ls' in the variable OUTCode:OUT = `ls` echo $OUT
Single-quotes will print verbatim whatever is within them (including escape characters), while double-quotes will interprete escape characters:
Code:echo '\n' # This will print \n to the screen echo "\n" # This will print a new line
Cool, that's what I call a precise answer thanks a bunch.
Now I think I see what my problem is. I guess I will need to nest the quotes. That's not possible, is it?
This is what I've got a problem with
This works if I call it from the command promt put it has to be called with sh -c from within a menu. So I would need another pair of quotes around it, don't I ???Code:gkrellmPID=`ps ax|grep [g]krellm|awk '{print $1}'`; \ if [ -z ${gkrellmPID} ]; \ * * *then echo "AddToMenu DesktopMenu Start gkrellm Exec exec gkrellm -g +0+460"; \ * * *else echo "AddToMenu DesktopMenu Stop gkrellm Exec exec kill $gkrellmPID"; \ fi;
This is technically incorrect.Code:echo '\n' # This will print \n to the screen echo "\n" # This will print a new line
In a programming language, yes this is true, but the echo command works differently. If you want to interpret the escaped characters, you have to use the -e option, that is all that matters.
I know why it behaves like that, but ultimately it's not important.Code:echo -e '\n' # This will print a new line, and echo -e "\n" # so will this. But these two won't: echo '\n' echo "\n"
Demian, I'm not sure what's wrong with your quotes. The only problem I can see with your script is that the way you end every line with a semi colon and then a backslash (; \) accomplishes nothing (they in fact cancel each other out to produce the same effect as if there was nothing there).
Uhm, yeah, I guess that's a bit redundant. You're right, the above script works. But now I have to call the script like this: sh -c 'script goes here'. So I need to quote the whole thing again. Well, actually I want to call this script with the PipeRead command from within an fvwm menu which basically is equivalent to the sh -c thing. So the menu item looks like this:Demian, I'm not sure what's wrong with your quotes. The only problem I can see with your script is that the way you end every line with a semi colon and then a backslash (; \) accomplishes nothing (they in fact cancel each other out to produce the same effect as if there was nothing there).
Actually I realize that I do need the ; \ because otherwise fvwm tries to interpret the lines stating with if, then,... and doesn't know what to do. Anyway, I tried to escape the single quotes around the awk "script" but that doesn't work. The message that's spit to the console from the above script is sh: [: too many arguments.Code:AddToFunc MakeDesktopMenu + I DestroyMenu recreate DesktopMenu + I PipeRead 'gkrellmPID=`ps ax|grep [g]krellm|awk \'{print $1}\'`; \ * * *if [ -z ${gkrellmPID} ]; \ * * * * * *then echo "AddToMenu DesktopMenu Start-gkrellm Exec exec gkrellm -g +0+460"; \ * * * * * *else echo "AddToMenu DesktopMenu Stop-gkrellm Exec exec kill $gkrellmPID"; \ * * *fi;'
I was thinking of an alternative way to get the PID of a program that doesn't require two different sets of quotes but couldn't com up with anything.
That would be what your (currently nonexistant) bangpath is for.But now I have to call the script like this: sh -c 'script goes here'.
Well first of all, why not just put it into a script and then have Piperead run the script??Well, actually I want to call this script with the PipeRead command from within an fvwm menu which basically is equivalent to the sh -c thing.
Putting it into it's own script would fix that.Actually I realize that I do need the ; \ because otherwise fvwm tries to interpret the lines stating with if, then,... and doesn't know what to do.
The fix for this is to give less arguments to [.The message that's spit to the console from the above script is sh: [: too many arguments.
($gkrellmPID has a space in it and [ is barfing over it).Code:if [ -z "${gkrellmPID}" ]
Bookmarks