Shell get file suffix

Source: Internet
Author: User

Introduce a file in a makefile file by using include

Include $ (shell./getname)

and the contents of the GetName are as follows:

pwd=$ (PWD);

if ["${pwd#*/zloader.}" = "$pwd"];then

Echo Makefile.cpci

Else

echo Makefile.${pwd#*/zloader.}

fi

I've never read ${pwd#*/zloader.} What does this mean, and then it turns out that what you get is the suffix name of the make file.

If it's pwd=/xxx/yyy/zloader.bios, then you need to get Makefile.bios, where ${pwd#*/zloader.} = BIOS. Where ${AAA#BBB} is a regular expression, and '/* ' represents all of the preceding Zloader in the path string in the PWD.

Explain:

${parameter#pattern}

Substitute the value of parameter with patternremoved to the left side. The smallest portion of the contents of parametermatching pattern is removed. Shell filename substitution characters (*,?, [...],!, and @) May is used in.

Try a script under Linux to prove it.

#!/bin/sh

Mkdir-p Zloader./xxdir

CD Zloader./xxdir

pwd=$ (PWD)

echo "pwd = $pwd"

echo "This'll substitue pwd about the Patternzloader., into NULL"

echo "${pwd#*/zloader.}"

Cd.. /..

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.