Re: Ksh quoting

From: Chris F.A. Johnson (cfajohnson_at_gmail.com)
Date: 10/14/05


Date: Fri, 14 Oct 2005 11:50:43 -0400

On 2005-10-14, Ian Wilson wrote:
> I have a script that should use an appropriate pager (less, pg, etc) for
> the platform so I want to pick one and use it as a variable later in the
> script. However I can't get the quoting right ...
>
> #!/bin/ksh
> if [[ -x /usr/bin/less ]] ; then
> pager="/usr/bin/less"
> else
> pager="/usr/bin/pg"
> fi
> # ...
> $pager foo.txt
>
> The above works OK but I want pager to contain
> /usr/bin/less -S +G -Ps"Press Q to quit"
>
> I've tried various methods of quoting the quotes:
> pager='/usr/bin/less -S +G -Ps"Press Q to exit " '
> pager='/usr/bin/less -S +G -Ps"""Press Q to exit """ '
> pager='/usr/bin/less -S +G -Ps\"Press Q to exit \" '
> pager="/usr/bin/less -S +G -Ps\"Press Q to exit \" "
> pager="/usr/bin/less -S +G -Ps"\""Press Q to exit "\"" "
> pager='/usr/bin/less -S +G -Ps'\''Press Q to exit '\'' >'
> (and some mind-numbing attempts at quoting the quoting of the quotes).
>
> In each case less sees the "Q", "to", "exit" as filenames, clearly I'm
> not managing to protect the string from the quote-removal part of ksh
> parsing - or maybe from one of the word-separation phases.
>
> I'd be very grateful for any clues!
>
> Bonus points for getting less to prompt with the Q in quote-marks :-)

LESS="-S +G -PsPress \"Q\" to exit "
export LESS
pager=/usr/bin/less

-- 
    Chris F.A. Johnson                     <http://cfaj.freeshell.org>
    ==================================================================
    Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
    <http://www.torfree.net/~chris/books/cfaj/ssr.html>


Relevant Pages

  • Re: Text editing
    ... In reality these are more like ... Project Gutenburg and it is here that the quoting grates with me in some ... that quotes were closed. ... You could then run the script on the full data and you'd only ...
    (uk.comp.sys.mac)
  • Ksh quoting
    ... I have a script that should use an appropriate pager for ... However I can't get the quoting right ... ... Bonus points for getting less to prompt with the Q in quote-marks :-) ...
    (comp.unix.shell)
  • Re: Issue with bc and echo in script
    ... the script, ... runs fine...how do I get the script to run without using the quotes on the ... command line ... unchanged, and quoting does this. ...
    (comp.unix.shell)
  • Re: Quoting Characters-how to avoid having them on replies?
    ... I'm guessing you're talking about plain text messages with ">" quoting ... On your computer, go to /Applications/AppleScript/, and open Script Editor. ... if window 1 = main window then ... with the quoting characters gone and the insertion point on top. ...
    (microsoft.public.mac.office.entourage)
  • =?Utf-8?Q?RE:_RE:_RE:_Custom_GridView_Cont?= =?Utf-8?Q?rol_=E2=80=93_Postback_Problems?=
    ... does work even when using Template Pager. ... > | composite control), and that works for the most part. ... > |> the clientside postback script and the submit form fields, ... > |> Microsoft Online Support ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)