How to use shell scripts to change the current working path
Source: Internet
Author: User
How to use shell scripts to change the current working path-Linux general technology-Linux programming and kernel information. The following is a detailed description. 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 is optional)
Cd/
Pwd
Echo "complete"
However, during actual execution, the path is changed, 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.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service