There are three methods for executing Shell scripts.
Bash Script Name
Sh Script Name
Chmod + x Script Name
Use the following statement to test
# A. sh (the extension cannot be used) cd/pwdecho "complete"
|
However, the path is changed during the execution, but the final result is that the path is not changed.
[fedora@localhost ~]$ bash a.sh/complete[fedora@localhost ~]$
|
Cause analysis:
When the script is executed, only a sub-process is opened under the current shell. The directory switch operation is only valid for subsequent commands in the process, but cannot change the directory of the parent process.
Solution:
Method 1:
Use source a. sh.
Method 2:
[fedora@localhost ~]$ cd ~[fedora@localhost ~]$ chmod u+x a.sh[fedora@localhost ~]$ . ./a.sh /complete[fedora@localhost /]$
|
For $ ../a. sh
The first point is the bash Internal Command, indicating to run in the Current shell
"./A. sh" is the command parameter, that is, the script to be executed.
Note: there must be a space between two points.