Cannot jump to selected directory #3738
-
I wrote the simple file manager script:
Working great, except cd to selected directory. Nothing happens when I select directory. What is wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
When you execute your program, it runs in a subshell; thus, directory changes won't affect the parent shell from which you called your script. However, you can source path/to/your/script Afterward, call the function. This method executes the script in the current shell, not a new one1. Footnotes |
Beta Was this translation helpful? Give feedback.
-
Thx. Working now. |
Beta Was this translation helpful? Give feedback.
When you execute your program, it runs in a subshell; thus, directory changes won't affect the parent shell from which you called your script.
However, you can
source
it. Wrap your code in a function, then use:source path/to/your/script
Afterward, call the function. This method executes the script in the current shell, not a new one1.
Footnotes
Bash Guide for Beginners - 2.1.3. Executing the script ↩