real shell script - the script to pass parameters and basic operations

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_25908839/article/details/86566869

Objective: To pass parameters to the script and the basic budget

Ideas: first pass after the operation parameters

Parameter passing: two integers incoming command line, such as the $ bash demo.sh ab; shell script $ 1 and $ 2 for these two parameters
calculation: $ [] $ (()  ) expr let

#!/bin/bash
#Date:		2019.01.19
#Author:	TURF
#Mail:		[email protected]
#Function:	pass parameters to shell script to perform operations
#Version:	1.0


echo "The First para: $1"
echo "The First para: $2"
a=$1
b=$2
#求两个参数的和
echo "两个参数的和: " 
echo "a + b = "$[ $a + $b ]
#求两个参数的差
echo "两个参数的差: "
echo "a - b = " $(( $a - $b )) "OR" "b - a = "`expr $b - $a`
#求两个参数的积
echo "两个参数的积: "
echo "a * b = " $(($a*$b))
#求两个参数的商
echo "两个参数的商"
echo "a / b = " $(( $a / $b )) "OR" "b / a = "`expr $b / $a`

$ Bash demo.sh in the command input line 23 to give the following results

First para of The: 2
of The First para:. 3
two arguments: 
A + B =. 5
two difference parameters: 
A - B = B -1 OR -. 1 = A
product of two parameters: 
A = B *. 6
Suppliers for two parameters
a / b = 0 OR b / a = 1
 

Guess you like

Origin blog.csdn.net/qq_25908839/article/details/86566869