A: Basic review
1: File Empty
[Email protected] test]$ >log.txt
2: Normal and Error redirect output
Normal and error append output to same place
[Email protected] test]$ ifconfig &>>log.1
Normal output redirect
[Email protected] test]$ ifconfig >log
Error output redirection
[Email protected] test]$ ifconfig 2>log.2
3: Command execution control
Sleep for 1 seconds
[[email protected] test]$ sleep 1
4:bash Script Start
The bash script must start with this, declaring the command interpreter path
#!/bin/bash
5: User interaction, read user input information and save to variable
Syntax: Read variable 1 variable 2
[[Email protected] bash] $vi read.sh
!#/bin/bash
Echo-n "Please input your name:"
Read name
echo "Your name is: $name"
[[Email protected] bash] $bash read.sh
[[email protected] bash] $please input your name: Jackchen
Your name Is:jackchen
Two: Built-in variable use
Built-in variables: The system is already existing variables, can be used directly. When executing a script, it can be passed inside the script with parameters.
Built-in variables are: $ The script itself
$ .... Parameters
$# a total of several parameters
Exercise 1: inside.sh script as follows, carry 3 parameters 1, 2, 3, print $0,$1,$2,$ #的值
650) this.width=650; "Title=" inside. JPG "src=" http://s1.51cto.com/wyfs02/M01/7E/72/wKiom1b_wmWzf0BGAACeTiIIwsQ155.jpg "alt=" wkiom1b_ Wmwzf0bgaacetiiiwsq155.jpg "/>
Exercise 2: Write a bash script that implements two numbers of additions? Write a calculator?
Write a bash script
[[Email protected] bash] $vi add.sh
#!/bin/bash
Echo $[$1+$2]
[[Email protected] bash] $bash add.sh 3 2
5
Write a calculator
[[Email protected] bash] $vi calc.sh
#!/bin/bash
echo "$" |BC
[[Email protected] bash] $bash calc.sh 2+3*5-6/2
14
This article is from the "Reminder Flower Rain" blog, please make sure to keep this source http://chenwen.blog.51cto.com/771416/1759945
Linux Advanced Bash Programming quad (built-in variable)