Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: convolutions



On Nov 6, 10:33pm, Ray Andrews wrote:
} Subject: Re: convolutions
}
} I did indeed edit it a bit.  Here's the pasted actual test file:
} 
} test2 ()
} {
}      echo "$(eval echo "\${$(cat junk1)}")" >! junk2
}      cat junk2
} }
} 
} ... which works as advertised.

That will fail with "bad substitution" for anything more than a single
word in the file "junk1".

torch% echo "this is some text" > junk1
torch% test2 ()
{
     echo "$(eval echo "\${$(cat junk1)}")" >! junk2
     cat junk2
}
torch% test2
(eval):1: bad substitution

torch% 

You can't just throw ${ } around any arbitrary thing and have it act
like a parameter expansion -- which is what is happening during the
eval when you have used \$ in the original expression:

torch% setopt xtrace verbose
torch% test2
test2
+Src/zsh:25> test2
+test2:2> cat junk1
+test2:2> eval echo '${this is some text}'
(eval):1: bad substitution
+test2:2> echo ''
+test2:3> cat junk2

torch% 

-- and you don't even need it there in this case:

torch% test2 ()
{
     echo "$(eval echo "$(cat junk1)")" >! junk2 
     cat junk2
}
torch% some=OTHER
torch% echo 'this is $some text' >| junk1
torch% test2
this is OTHER text
torch% 

} >      print -R "${(e)$(<in_file)}" >| out_file
} 
} Does the trick, thanks, it's no shorter, but much more respectable. 
} print has many tricks up it's sleeve.

Sigh.  No, "-R" is explicitly telling "print" not to do any tricks at
all.  It's the (e) parameter expansion flag that's doing the work.



Messages sorted by: Reverse Date, Date, Thread, Author