The variables of shell learning

Source: Internet
Author: User

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

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.