Basename dirname read, basenamedirname in shell

Source: Internet
Author: User

Basename dirname read, basenamedirname in shell
1. basenameIs the name left after the directory is removed
Example: shell> temp =/home/temp/1. test
Shell> base = 'basename $ temp'
Shell> echo $ base
Result: 1. test
2. dirnameIs to retrieve the Directory
Example: shell> temp =/home/temp/1. test
Shell> dir = 'dirname $ temp'
Shell> echo $ dir
Result:/home/temp

Another method:
$ {Var ### */} is to remove the last/and left content of the variable var.

$ {Var %/*} is to remove the last/and right content of the variable var.

3. read

#! /Bin/bash
Echo-n "Enter your name:" // the function of parameter-n is not to wrap the line, and echo is to wrap the line by default.
Read name // input from the keyboard
Echo "hello $ name, welcome to my program" // display information
Exit 0 // exit the shell program.
//********************************
Because the read command provides the-p parameter, you can specify a prompt directly in the read command line.
Therefore, the preceding script can be abbreviated as the following script ::
#! /Bin/bash
Read-p "Enter your name:" name
Echo "hello $ name, welcome to my program"
Exit 0


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.