I was looking over some ksh code and came across a line I didn't think would work. Upon testing the code, it did work, but I am not sure why.
If it matters, this is running on an AIX 5.3 system.
The line in the code was:
scriptname=$(\basename $0)
I didn't think it would work because of the backslash in front of the basename
command, but when I tested the scriptname
variable, it had the correct value.
I did some further testing on the command line:
$ echo $(\echo test)
test
$ echo $(\echo \test)
test
$ echo $(\e\c\h\o \test)
test
$ echo `\e\c\h\o \test`
test
$ echo $(\echo "\test")
est
I tried it outside of the command subtitution, and it still didn't work like I thought it would:
$ \echo \testi\ng
testing
$ \echo "\testi\ng"
esti
g
The last one is the only one that makes some sense to me.
Does Kornshell just ignore the backslashes, or maybe just convert them to the character in front of the backslash? I assumed that putting a \n
anywhere on the command line would be a newline, but apparently only if it is in quotes, or \\n
.
Can someone explain what ksh does with backslashes on the command line?
Either way, I assume the better way to write the command I originally questioned would be:
scriptname=$(basename $0)
instead of:
scriptname=$(\basename $0)
Does it matter?
Thanks in advance!
If any part of a command name is quoted then ksh will ignore any aliases when selecting what to execute.
I presume that is why the original script was using \basename.