Artificial intelligent assistant

CD $Variable not working when used in a (Bash) Shell Script File name: Test.sh #!/bin/bash ZDir="$(echo /usr/src)" cd "$ZDir" When I execute the script `./Test.sh`, the command `cd` doesn't do anything. If I try to do it directly in the bash terminal, it works like a charm. Also, echo, used inside and outside the script, returns me the correct value (`/usr/src`). Does anyone know why this happens? Again: `cd $ZDir` works if used outside the script, directly in the terminal... Edit: Could'nt find the answer on the "duplicate" one but that G-Man user right there answered exactly what i needed to do. Just included a && followed by the next command i needed to do and worked. Functions can also be used for this... cdZDir() { cd /usr/src; make; make install; } Then just call in the function.

`cd` only affects the _current_ shell and its descendants. Shell scripts are run in new shell processes, so a `cd` in a script affects only the remainder of the execution of the script, and any programs it runs.

* If you put commands like `pwd` and `ls` _into the script,_ after the `cd`, you’ll see that the `cd` has succeeded _in the script._
* If you say `**.** ./Test.sh`, your current (main) shell process will read `Test.sh` and execute the commands therein. Then you’ll see that your current (main) shell process will be in the new directory.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy d6595abe7c76a91f142af3e9be5e7307