Learn the shell bit by bit

Source: Internet
Author: User

1. Get the name of the shell script

${BASH_SOURCE-$0}

2. Get the path to the shell script

DirName "${bash_source-$0}"

This path is not necessarily the true path of the script, for example, assuming that the command is in file/home/hubavyn/test.sh.

Perform the following actions:

CD/HOME/HUBAVYN/A (Suppose A is a folder)

Sh.. /test.sh (this time execute the above dirname command to get the result just ...)

And if you want to get the true path of the script (/home/hubavyn), do the following:

Path= ' DirName "" ${bash_source-$0} '

Real_path= ' CD ' Path ' >/dev/null;pwd '

This is the time to get Real_path is/home/hubavyn. The benefit is that the script can be deployed flexibly, and it is easy to get the location of other files deployed with the script.

3. Add in a script. < The name of another script >

Plus. Indicates that another script is equivalent to executing in the current script, such as a variable assignment in another script, as well as in the current script.

Learn the shell bit by bit

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.