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