Re: Ksh quoting
From: Chris F.A. Johnson (cfajohnson_at_gmail.com)
Date: 10/14/05
- Next message: RolandRB: "Re: I want to match on an odd number of characters"
- Previous message: John L: "Re: pattern search"
- In reply to: Ian Wilson: "Ksh quoting"
- Next in thread: Ian Wilson: "Re: Ksh quoting"
- Reply: Ian Wilson: "Re: Ksh quoting"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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>
- Next message: RolandRB: "Re: I want to match on an odd number of characters"
- Previous message: John L: "Re: pattern search"
- In reply to: Ian Wilson: "Ksh quoting"
- Next in thread: Ian Wilson: "Re: Ksh quoting"
- Reply: Ian Wilson: "Re: Ksh quoting"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|