unix - Bad use of parentheses -
i've been stuck on hours:
cd /dir1 (cd $home); pwd; why pwd still /dir1 , didn't go home directory?
parentheses start subshell: shell calls fork, , commands inside parentheses executed in subprocess. parent process waits subprocess exit resumes execution. what's happening is:
- execution of
cd /dir1: shell performschdir("/dir1"). - execution of parentheses: shell calls
fork, parent process waits child exit. - execution of
cd $home: subshell performschdir("/home/jurgen"). - the subshell has run out of commands, exits.
- the subshell has exited,
waitcall in parent returns. - execution of
pwd: shell prints current directory,/dir1.
Comments
Post a Comment