Shell gets the current path

Source: Internet
Author: User

Prg= "$"while do  ls= ' ls-ld ' $PRG "'  link= ' expr ' $ls": ' .*-> \ (. *\) $ ' `   if expr "$link": '/.* ' >/dev/null; then    PRG= "$link"  else C15/>PRG= ' dirname ' $PRG '/' $link '  fidoneprgdir= ' dirname ' $PRG '-Z ' $CATALINA _home "] && catalina_home= ' CD $PRGDIR/:" >/dev/null"Catalina_home is $CATALINA _home";
#此处的RPG抓取的是文件名, because it could be a symbolic link, the function of a looping statement is to find the file's true source path
-H is used to determine if the $prg file exists and is a symbolic link
Ls-ld "$PRG" to view the details of the current directory of the running program, but only the directory, excluding subdirectories and files under the directory

link= ' expr ' $ls ': ' .*-> \ (. *\) $ '
Expr means to match a string to a pattern and return the string to which it is matched
Or calculate the number of characters to match according to a pattern. Commonly used: expr value:expression


The "$ls" represents the contents of the variable ls.


' .*-> \ (. *\) $ ' This part is a regular expression,. * Part denotes any character, and is the actual two characters, the soft link in Linux will use the Ls-al command to list the file, with "soft link-to-real file" way to show the soft link and The actual file to which it is linked. The $ here represents the end of the line \ (that is, because (the shell belongs to a special symbol, you need to use escape; \) is also escaped as);

The entire ' expr ' $ls ': ' .*-> \ (. *\) $ ' means the actual file or the real directory to which the soft connection was taken.

[ -z "$CATALINA_HOME" ] && CATALINA_HOME=`cd"$PRGDIR/..">/dev/nullpwd` 判断变量$CATALINA_HOME是否存在,不存在则给予附值

Shell gets the current path

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.