K
Kuhl
Hi, all:
Backticks `` are supposed to be able to transfer the result of shell
commands to Perl variable.
But it's very confusing that it does not behave in the way that I
think it should do.
$current_path=`pwd`; This works.
$current_path=`echo $cwd`; This does not work.
But in fact, pwd is aliased to echo $cwd. Details see below.
What's the issue? How to fix it?
Thanks.
# which pwd
pwd: aliased to echo $cwd
# pwd
/home/user/shell
# echo $cwd
/home/user/shell
#!/usr/bin/perl
$current_path=`pwd`;
print "\nCurrent path is $current_path .\n";
$current_path=`echo $cwd`;
print "\nCurrent path is $current_path .\n";
$current_path=`echo \$cwd`;
print "\nCurrent path is $current_path .\n";
$current_path=`"echo $cwd"`;
print "\nCurrent path is $current_path .\n";
exit 0;
But the result of this script is:
Current path is /home/user/shell
..
Current path is
..
Current path is
..
sh: line 1: echo : command not found
Current path is .
#
Backticks `` are supposed to be able to transfer the result of shell
commands to Perl variable.
But it's very confusing that it does not behave in the way that I
think it should do.
$current_path=`pwd`; This works.
$current_path=`echo $cwd`; This does not work.
But in fact, pwd is aliased to echo $cwd. Details see below.
What's the issue? How to fix it?
Thanks.
# which pwd
pwd: aliased to echo $cwd
# pwd
/home/user/shell
# echo $cwd
/home/user/shell
#!/usr/bin/perl
$current_path=`pwd`;
print "\nCurrent path is $current_path .\n";
$current_path=`echo $cwd`;
print "\nCurrent path is $current_path .\n";
$current_path=`echo \$cwd`;
print "\nCurrent path is $current_path .\n";
$current_path=`"echo $cwd"`;
print "\nCurrent path is $current_path .\n";
exit 0;
But the result of this script is:
Current path is /home/user/shell
..
Current path is
..
Current path is
..
sh: line 1: echo : command not found
Current path is .
#