A variable definition
1 explicitly defined variable=xxx no spaces
2 Read variable Reading
The following two lines of code are written, reading name and namefamily
Read-p "Please input your name:" Name
Read-p "Please input your whole name:" Name family
Run under
[Email protected] shell]#./var.sh
Please input your Name:liuliancao
Your name Is:liuliancao
Please input your Name:liu Liancao
Your name Is:liu Liancao
Please input your whole Name:liancao Liu
Your name is Liancao,your family is Liu
Please input your whole Name:liancao
Your name is Liancao,your family is
Please input your whole name:liancao l IU
Your name is Liancao,your family is L IU
The number of visible variables and the number of inputs, the allocation is exactly, if the number of variables, then the following variable is empty, the number of variables is less, then the oldest is the eldest (eat the most).
3 reading from a file
[[email protected] shell]# Read Message < TXT
[Email protected] shell]# echo $message
Hello,i Amliuliancao because it is text redirection, and TXT text lines have line breaks, so there is only one line at this time, if you want to continue to use the loop
[[email protected] shell]# while read message
> Do
> Echo $message
> Done < txt
Hello,i am Liuliancao
This is a test
4 command substitution
1 #!/bin/bash
2 #
Time= ' Date +%c '
3 echo "Now Time is $time"
Execution results
[Email protected] shell]#./com.sh
Now time is Sat 12:26:49 PM CST
5 Position parameters
Common with
$ full file name basename can take the basic name
The first variable content, and so on
[Email protected] All variables are stored in an array $* all variables, grouped into large strings
6 Deleting a variable
unset variable Name
The variables of shell learning