Search code examples
bashshellcd

Stay in directory changed after ending of bash script


My bash script:

#!/bin/bash
cd /tmp

Before running my script:

pwd: /

After running my script:

pwd: /

After runnig my script trough sourcing it:

pwd: /tmp

How I can stay at the path from the script without sourcing it ?


Solution

  • You can't. Changes to the current directory only affect the current process.