Hi,
ToddAndMargo wrote:
> $ watch -n 2 "ls -al /lin-bak | grep -i OurStuff.tar | awk
'{print $9, $5}'"
> watch: failed to parse argument: 'ls -al /lin-bak | grep -i OurStuff.tar |
> awk '{print , }'': Invalid argument
The problem is that the '-quotes, $9 and $5 are in "-quotes. The '-quotes
are thus ignored and $9,$5 are evaluated already by the shell parser which
analyses the arguments of "watch". Their value is empty when interpreted
as shell parameters.
Actually they are meant to be arguments for awk, not shell variables.
Ed Greshko wrote:
watch -n 2 "ls -al /tmp | grep -i OurStuff.tar | awk '{print
\$9, \$5}'"
Indeed, this keeps the shell from interpreting the $-signs.
Personally, i prefer closing the "-quotes and opening '-quotes for the
words which begin by literal $-signs. When done with the dollars, i end
'-quotation and begin "-quotation again:
watch -n 2 "ls -al /tmp | grep -i OurStuff.tar | awk '{print "'$9,
$5'"}'"
Quote range:
"""""""""""""""""""""""""""""""""""""""""""""""""
'''''' ""
Testing with echo:
$ echo "ls -al /tmp | grep -i OurStuff.tar | awk '{print "'$9,
$5'"}'"
ls -al /tmp | grep -i OurStuff.tar | awk '{print $9, $5}'
----------------------------------------------------------------------------
If i had to produce such strings by a program, i would generally wrap them
in `-quotes and use "-quotes only to protect literal '-quotes from the shell
parser:
watch -n 2 'ls -al /tmp | grep -i OurStuff.tar | awk
'"'"'{print $9, $5}'"'"
Quote range:
'''''''''''''''''''''''''''''''''''''''''
" '''''''''''''' "
This needs only very simple program logic.
(Also it is well suitable for human but mostly deterministic users.)
Have a nice day :)
Thomas