Re: Shell scripting question regarding quoting
bash: foobar=op\\q; echo ${foobar///} you don't need sed for this. foobar can be $1 etc (write ${1//...}) Peter = To unsubscribe, send mail to [EMAIL PROTECTED] with the word unsubscribe in the message body, e.g., run the command echo unsubscribe | mail [EMAIL PROTECTED]
Re: Shell scripting question regarding quoting
On Tue, 17 May 2005 12:27:55 +0300, Shachar Shemesh [EMAIL PROTECTED] wrote: I have a bourne shell script that defines a function dosomething. Dosomething receives a string, and passes is along to a subshell for processing (currently by doing sh -c $cmdline). The problem is that when I do: dosomething a\\b $cmdline gets: a\b (which is ok) but the subshell gets: ab Which is not. Is there a builtin shell function that quotes special characters for passing through a context that does dereferencing? There is no problem with bash omitting \. There is a bigger problem with arguments with spaces in them. How do you set `cmdline' from the script arguments ? Here is an example of small script that call itself with demonstration of preserving its arguments. #! /bin/bash -e # Compile by: /bin/sh -e $* 3 1=abc 2=a\b 3=a\\b 4=with 3 spaces '5=quoteit' 6=apos'in #== echo -E (echo -E) Called as $0 $@# Show with escape chars as is echo -e (echo -e) Called as $0 $@# Show translated escape sequence CNT=$1 # how many times to call shift # ignore the 1st arg if [ 0$CNT -gt 1 ] ; then # call next if 1 NXT=`expr $CNT - 1` CMDLINE= for ARG in $@# do for each argument do # convert space to \x20 CARG=`echo -E $ARG | sed -e 's/ /x20/g'` CMDLINE=$CMDLINE $CARG # store in new command call done $0 $NXT $CMDLINE # call once more (with decreased count) fi echo $CNT DONE $* # show with arguments exit 0 ## tst.sh ## And here is the output when called by: /bin/sh -e tst.sh 3 1=abc 2=a\b \ 3=a\\b 4=with 3 spaces '5=quoteit' 6=apos'in (echo -E) Called as tst.sh 3 1=abc 2=a\b 3=a\\b 4=with 3 spaces 5=quoteit 6=apos'in (echo -e) Called as tst.sh 3 1=abc 2=a 3=a\b 4=with 3 spaces 5=quoteit 6=apos'in (echo -E) Called as ./tst.sh 2 1=abc 2=a\b 3=a\\b 4=with\x20\x20\x203\x20spaces 5=quoteit 6=apos'in (echo -e) Called as ./tst.sh 2 1=abc 2=a 3=a\b 4=with 3 spaces 5=quoteit 6=apos'in (echo -E) Called as ./tst.sh 1 1=abc 2=a\b 3=a\\b 4=with\x20\x20\x203\x20spaces 5=quoteit 6=apos'in (echo -e) Called as ./tst.sh 1 1=abc 2=a 3=a\b 4=with 3 spaces 5=quoteit 6=apos'in 1 DONE 1=abc 2=a 3=a\b 4=with 3 spaces 5=quoteit 6=apos'in 2 DONE 1=abc 2=a 3=a\b 4=with 3 spaces 5=quoteit 6=apos'in 3 DONE 1=abc 2=a 3=a\b 4=with 3 spaces 5=quoteit 6=apos'in Ehud. -- Ehud Karni Tel: +972-3-7966-561 /\ Mivtach - Simon Fax: +972-3-7966-667 \ / ASCII Ribbon Campaign Insurance agencies (USA) voice mail and X Against HTML Mail http://www.mvs.co.il FAX: 1-815-5509341 / \ GnuPG: 98EA398D http://www.keyserver.net/Better Safe Than Sorry To unsubscribe, send mail to [EMAIL PROTECTED] with the word unsubscribe in the message body, e.g., run the command echo unsubscribe | mail [EMAIL PROTECTED]
Shell scripting question regarding quoting
Hi all, I have a bourne shell script that defines a function dosomething. Dosomething receives a string, and passes is along to a subshell for processing (currently by doing sh -c $cmdline). The problem is that when I do: dosomething a\\b $cmdline gets: a\b (which is ok) but the subshell gets: ab Which is not. Is there a builtin shell function that quotes special characters for passing through a context that does dereferencing? thanks, Shachar -- Shachar Shemesh Lingnu Open Source Consulting ltd. Have you backed up today's work? http://www.lingnu.com/backup.html = To unsubscribe, send mail to [EMAIL PROTECTED] with the word unsubscribe in the message body, e.g., run the command echo unsubscribe | mail [EMAIL PROTECTED]
Re: Shell scripting question regarding quoting
On 5/17/05, Shachar Shemesh [EMAIL PROTECTED] wrote: Hi all, I have a bourne shell script that defines a function dosomething. Dosomething receives a string, and passes is along to a subshell for processing (currently by doing sh -c $cmdline). The problem is that when I do: dosomething a\\b $cmdline gets: a\b (which is ok) but the subshell gets: ab Which is not. Is there a builtin shell function that quotes special characters for passing through a context that does dereferencing? I'm not aware of a Bourne shell function to do this. I also don't see a Bash function to do this (are you prepared to depend on bash-ism?) A simple perl-style solution would be to just quote it yourself through sed, something like: quotedcmdline=`echo $cmdline | sed -e s:[\$']::g` thanks, Shachar Cheers, --Amos To unsubscribe, send mail to [EMAIL PROTECTED] with the word unsubscribe in the message body, e.g., run the command echo unsubscribe | mail [EMAIL PROTECTED]