Variables in the shell using a summary _linux shell

Source: Internet
Author: User
Tags svn

The definition of a variable can only begin with a letter and an underscore, case-sensitive, and may contain a numeric letter underline. See Official Handbook

Copy Code code as follows:

[Root@svn shell_example]# yourname= ' Linux '
[Root@svn shell_example]# Echo $yourname
Linux
[Root@svn shell_example]# yourname= "Linux"
[Root@svn shell_example]# echo "The variable is $YourName"
The variable is Linux

Gets the script for the current date, commonly used in log cutting, in order to distinguish daily log files
Like the following generation April 27, 2015
Copy Code code as follows:

[Root@svn shell_example]# echo ' Date +%y%m%d '
20150427
[Root@svn shell_example]# Cat today.sh
#!/bin/bash

today= ' Date +%a '
Year= ' date +%y year%m month%d days '
echo "Today is $YEAR, $TODAY"

[ROOT@SVN shell_example]# SH today.sh
Today is April 27, 2015, Monday


From the keyboard to obtain user input, the following script executes the script directly wait for the transfer input, until the user input completes and returns, the script obtains the user's input and prints the result.
Copy Code code as follows:

[Root@svn shell_example]# Cat var.sh
#!/bin/bash

Read MyVar
echo "MyVar is $myvar


Implementation results are as follows
[ROOT@SVN shell_example]# SH var.sh
Linux
MyVar is Linux
[/code]
Get user input from keyboard with prompt information
Copy Code code as follows:

#!/bin/bash
#从键盘获取用户信息, and print it out.
Echo-n ' Enter Your Name: ' #-n option indicates no line wrapping.
Read name
echo "Hi $name"

SH name.sh
Enter Your Name:linux
Hi Linux


Upgrade script, which successfully accepts the user's 2-parameter surname and name, and prints the input on the screen
The code reads as follows
Copy Code code as follows:

[Root@svn shell_example]# Cat firstname.sh
#!/bin/bash
pw= "123"
Echo
echo "+======== User Login =========+"
Echo
Echo-n "Please enter your username:"
Read FName lname
Echo-n "Please enter your password:"
Read passwd
echo "Dear member $fname $lname, Hello!" You are logged in successfully "

[ROOT@SVN shell_example]# SH firstname.sh

+======== User Login =========+

Please enter your username: Nass Lee
Please enter your password: 123
Dear member Nass Li, Hello! You have logged in successfully

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.