Shell,shell script structure and execution method, data command, variables in shell script

Source: Internet
Author: User
What is a shell?
The shell is a scripting language aming_linux blog.lishiming.net
You can use logical judgments, loops, and other syntax
Functions can be custom-defined
The shell is a collection of system commands
Shell scripts enable automated operations, which can greatly increase our operational efficiency


Shell script structure and execution methods
Need to add #!/bin/bash at the beginning
Lines that begin with # are interpreted as explanatory notes
The name of the script ends with. SH and is used to differentiate between this is a shell script
There are two methods of executing
chmod +x 1.sh;./1.sh
Bash 1.sh
View the script execution process bash-x 1.sh
See if the script is syntactically incorrect bash-n 1.sh

Date command

Variables in shell scripts
You should use a variable instead when you use a string more frequently in your script and the string length is long
When using conditional statements, the variable if [$a-gt 1] is often used; Then ...; Fi
When referencing the result of a command, replace n= with a variablewc -l 1.txt
When writing and user interaction scripts, variables are also essential for read-p "Input a number:" N; Echo $n If you don't write this n, you can use $reply directly.
Built-in variables $, $ $, $ ... $ $ represents the script itself, the first parameter, the $ A second ... $ #Number of parameters
Mathematical Operation a=1;b=2; c=$ (($a + $b)) or $[$a + $b]

Shell,shell script structure and execution method, data command, variables in shell script

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.