double-quote, simple-quote and eval [Was: ybin and NetBSD]
On Tue, Jul 17, 2001 at 04:14:34AM -0800, Ethan Benson wrote:
> On Tue, Jul 17, 2001 at 01:27:23PM +0200, Edouard G. Parmelan wrote:
> > ## assign variables for configured menu options.
> > - [ "$usemount" = no -a "$bless" = yes ] && YB="yaboot GNU l $ofboot ,${BS}${BS}yaboot"
> > - [ "$usemount" = yes -o "$bless" = no ] && YB="yaboot GNU l $ofboot ,${OFDIR}yaboot"
> > - [ -n "$bsd" ] && OS=$(($OS + 1)) && BSD="bsd BSD b $bsd ,${BS}ofwboot.elf"
> > - [ -n "$macos" ] && OS=$(($OS + 1)) && MAC="macos MacOS m $macos ,${BS}${BS}:tbxi"
> > - [ -n "$macosx" ] && OS=$(($OS + 1)) && MX="macosx MacOSX x $macosx ,${OSXBOOT}"
> > - [ -n "$darwin" ] && OS=$(($OS + 1)) && DW="darwin Darwin d $darwin ,${BS}${BS}:tbxi"
> > - [ "$cdrom" = yes ] && OS=$(($OS + 1)) && CD="cd CDROM c cd: ,${BS}${BS}:tbxi"
> > + [ "$usemount" = no -a "$bless" = yes ] && YB="yaboot GNU l $ofboot ',${BS}${BS}yaboot'"
> > + [ "$usemount" = yes -o "$bless" = no ] && YB="yaboot GNU l $ofboot ',${OFDIR}yaboot'"
> > + [ -n "$bsd" ] && OS=$(($OS + 1)) && BSD="bsd BSD b $bsd ',${BS}ofwboot.elf $bsd_options'"
> > + [ -n "$macos" ] && OS=$(($OS + 1)) && MAC="macos MacOS m $macos ',${BS}${BS}:tbxi'"
> > + [ -n "$macosx" ] && OS=$(($OS + 1)) && MX="macosx MacOSX x $macosx ',${OSXBOOT}'"
> > + [ -n "$darwin" ] && OS=$(($OS + 1)) && DW="darwin Darwin d $darwin ',${BS}${BS}:tbxi'"
> > + [ "$cdrom" = yes ] && OS=$(($OS + 1)) && CD="cd CDROM c cd: ',${BS}${BS}:tbxi'"
>
> i am almost certain this quoting is broken. it will cause these
> values to not be expanded and thus taken litterally. i don't see why
> your making gratuitous changes here.
I don't agree. Inside double-quote " .... " a simple quote (') is a
normal character. I add simple quote to group into one argument and
proctect special shell caracters. Later, I use "eval" in place of
direct call.
FIRST=`eval $cmd`
After the following assignment:
BSD="bsd BSD b $bsd ',${BS}ofwboot.elf $bsd_options'"
the value of variable BSD is:
bsd BSD b hd:10 ',\\ofwboot.elf hd:11,/netbsd'
Let's see step by step what's append.
1. Setup our test environment
$ cat echo-args.sh
#!/bin/sh
while [ $# -gt 0 ]; do
echo "[$1]"; shift
done
$ BSD=`cat <<EOF
bsd BSD b hd:10 ',\\ofwboot.elf hd:11,/netbsd'
EOF`
$ echo $BSD
bsd BSD b hd:10 ',\\ofwboot.elf hd:11,/netbsd'
2. And now study argument passing
$ sh ./echo-args.sh $BSD
[bsd]
[BSD]
[b]
[hd:10]
[',\\ofwboot.elf]
[hd:11,/netbsd']
$ eval sh ./echo-args.sh $BSD
[bsd]
[BSD]
[b]
[hd:10]
[,\\ofwboot.elf hd:11,/netbsd]
RUOK ?
> > [ $(parseconf ck timeout) = 0 ] && timeout=`parseconf str timeout`
> > -[ $(parseconf ck bsd) = 0 ] && bsd=`parseconf str bsd`
> > +if [ $(parseconf ck bsd) = 0 ]; then
> > + tmp=`parseconf str bsd`
> > + bsd=`busybox expr "$tmp" : '\([^ ]*\)'`
> > + bsd_options=`busybox expr "$tmp" : "$bsd"'[ ]*\(.*\)'`
> > +fi
>
> no way dood, this is a GROSS hack. i won't depend on busybox in this
> manner.
Oops, sorry, I write "busybox expr" in place of "expr" to be sure that
in a buzybox environment it will work.
> sorry but i will not accept this patch.
Will you ?
--
Edouard G. Parmelan
http://egp.free.fr
Reply to: