View Single Post
Old 25th September 2010
cq04cw cq04cw is offline
New User
 
Join Date: Sep 2010
Posts: 5
Default

Quote:
Originally Posted by rocket357 View Post
The manpage states "a `\' followed by any of `$', ``', or `\' is stripped", so the first strip is for \\, leaving \$...but since \$ is in the list, too, the second \ is stripped as well, leaving $$_var, which is $aa, which evals to AAAA.

PHP Code:
set -x
$ `eval echo \\$$`
+ eval echo $$  
# BOTH \'s are stripped!
+ echo 31889
31889
/bin/ksh31889not found 
yes, it seem a letter clear to me. but if you add more backslash in front of it (see examples below), how you can read it ?

PHP Code:
b=`eval echo \\\$$_var# ex1
+ eval echo '$aa'
+ echo AAAA
b=AAAA
b=`eval echo \\\\$$_var# ex2
+ eval echo '\1018_var'
+ echo 1018_var
b=1018_var 
ex1:
The interpreter read in command line, and first two backslash is treated as \ literally, and \$ is treated as $ literally, $_var is replaced by $_var's value, "aa"
after first interpreted, the interpreter also find it there's \$ because of result of first read, and \$ is treated as $ literally ,
is it right ot understand it ?

ex2:
the interpreter read in , and first two backslash is treated \ literally , and following two backslash is also, and following two dollar sign is replaced by current pid value.
after first read(the first four backslash is interpreted \\), then this \\ is also interpreted \.

if ex1 and ex2 do make sense.
look at another example
PHP Code:
b=`eval echo \\\\\\$$_var# ex3
+ eval echo '\$aa'
+ echo '$aa'
b='$aa' 
ex3:
the interpreter read in command, the first two backslash is \, the second pair is also \, the third pair is also \, and the following two dollar sign is shell pid
after first read, the text is look like this: \\\1018_var, however, as you can see, the result is not expand $$ to pid, i think it interpret byte by byte, instead of read a line whole, like this: the first three pair backslash is interpreted three literal \, then \\\$$_var(assume it read byte by byte ) is interpreted as first two backslash is \ , third backslash and fourth dollar sign is literal $, and result of this is \$aa.

question 1: how the interpreter interpret command line , line by line or byte by byte, or otherwise?
question 2: why the \$ sequence not be interpreted, it's also in the list `$', ``', or `\'?
Reply With Quote