[sf-lug] shell quoting "exercise"

acohen36 acohen36 at SDF.ORG
Fri Nov 10 10:18:35 PST 2017

Michael Paoli <Michael.Paoli at cal.berkeley.edu> wrote:

> than stdin.  So ... taking those together ...
> $ ap_ip='!"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~'
> $ echo "$ap_ip  X" | sudo sh -c 'cat >> /dev/tty'
> !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~  X
> $
> So, now we can pass through any character unchanged ...
> well, except we may have to be concerned about how echo
> behaves, e.g. does $ap_ip start with dash (-) or contain backslash (\) ?
> The particular behavior may depend upon one's shell and echo.
> There's also a POSIXy way in non-ancient shells to do something
> effectively quite similar to echo, but with no further interpretation
> upon string.
> I'll leave that bit as exercise.  :-)

Well, another "exercise" is to type out at least twenty times _*without*_ 
cutting-and-pasting that command bit...
$ ap_ip='!"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~'
$ echo "$ap_ip  X" | sudo sh -c 'cat >> /dev/tty'
!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~  X

Again, _*no*_ cut-and-pasting methods allowed and you should strive for 
100% accuracy :-D

Should you become frustrated from your inaccuracy in this task, _only 
then_ are you allowed to cut-and-paste the cursing-out


acohen36 at sdf.org
SDF Public Access UNIX System - http://sdf.org

More information about the sf-lug mailing list