basename dirname read in the shell

Source: Internet
Author: User

1. basename is the name left after the directory is removed .
example:shell>temp=/home/temp/1.test
shell>base= ' basename $temp '
Shell>echo $base
The result is: 1.test
2. dirname is to fetch directory
example:shell>temp=/home/temp/1.test
shell>dir= ' dirname $temp '
Shell>echo $dir
The result is:/home/temp

another way to implement:
${var##*/} is to remove the last/and left contents of the Var variable

${var%/*} is the last/and the right of the variable var is removed

3.Read

#!/bin/bash
echo-n "Enter Your Name:"//Parameter-n is not wrapped, echo defaults to line wrapping
read name//input from keyboard
echo "Hello $name, Welcome to my program"//Display information
Exit 0//Quit Shell program.
//********************************
because the Read command provides the-p parameter, it allows you to specify a prompt directly on the read command line.
so the script above can be simply written in the following script:
#!/bin/bash
read-p "Enter Your Name:" Name
echo "Hello $name, Welcome to my program"
Exit 0


basename dirname read in the shell

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.