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 /usr/src && make && make install
command line into the script. (2) What’s there to know? You type a dot (.
). You type a space (
). You type the name of the script (with or without the./
). And you press “Enter”. – G-Man Says 'Reinstate Monica' Jul 10 '19 at 20:30