2

Example:

mainscript.sh

cd /mnt/something
./buildscripts/000-script.sh

000-script.sh

cd /mnt/otherthing
mkdir something
exit

2 Answers 2

3

Yes the executed process will not change the working directory of the parent process.

Example:

  • caller.sh

    #!/bin/bash
    echo -n "Caller 1 " ; pwd
    ./callee.sh
    echo -n "Caller 2 " ; pwd
    
  • callee.sh

    #!/bin/bash
    echo -n "Callee 1 " ; pwd
    cd /tmp
    echo -n "Callee 2 " ; pwd
    exit
    

Calling caller.sh will produce

Caller 1 /Users/corti/tmp
Callee 1 /Users/corti/tmp
Callee 2 /tmp
Caller 2 /Users/corti/tmp

As you see when printing Caller 2 the parent process has still the same working directory

0

The "child" is not remembering anything. This is just a basic concept that processes are started from their current working directory (cwd). If you look at /proc/* on a Linux-system you can see that entry for every process.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .