Re: "watch" and quotes problem?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
_______________________________________________
users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/users@xxxxxxxxxxxxxxxxxxxxxxx



[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux