When I execute the following command:
[root@localhost install_zone]# su nylws -c “cd ~/gamesvr/conf;echo $(pwd);pwd”
The output:
/opt/deploy_scripts/install_zone
/data/nylws/gamesvr/conf
So why the two paths are different? Thanks!
HowtoFusion - Linux Howtos and Tutorials.
When I execute the following command:
[root@localhost install_zone]# su nylws -c “cd ~/gamesvr/conf;echo $(pwd);pwd”
The output:
/opt/deploy_scripts/install_zone
/data/nylws/gamesvr/conf
So why the two paths are different? Thanks!
It’s because $(...)
is evaluated inside the double quotes by the parent shell, before the shell invoked by su
is even started. So the subshell sees:
cd ~/gamesvr/conf;echo /opt/deploy_scripts/install_zone;pwd
The best way to fix this is to use single quotes, which will pass the string literally to the subshell and not do any expansion on it:
su nylws -c 'cd ~/gamesvr/conf;echo $(pwd);pwd'