Switching the working directory through a script is just beginning to feel simple, and writing a CD statement directly in the script is done.
But it's not.
When executing a script, only a child process is opened under the current shell, and the operation of the switch directory is only valid for the relevant subsequent instruction in the process, but the directory of the parent process cannot be changed.
Therefore, when you have written the script and the call executes, your current working directory does not change.
Well, what about the solution?
There are two ways to do this (all in the same way that scripts are executed, and the script content remains a CD statement.) Assuming the script is change.sh):
- SOURCE change.sh
- . ./change.sh
The first point is the internal command of bash, which means running in the current shell
The following "./change.sh" is the argument to the command, which is the script to execute (note: There are spaces between two points)
Switch the current working directory by script under Linux