Practice One:
Pass three parameters to the script, the first is an integer, the second is an arithmetic operator, the third is an integer, the result of the calculation is displayed, and the two-bit precision is required to be preserved. Shaped like:./calc.sh 5/2
#!/bin/bash
#program:
#练习2个整数进行基本算术运算
#history 2016-10-21-14:10
Path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bash
Export PATH
Result= ' echo ' scale=2;$1 "| BC ' echo can continuously input parameters to the command behind the pipeline,
2 operations are separated by semicolons.
echo "The $1$2$3 is $RESULT."
Exercise two:
Write a script:
Determine the current host CPU manufacturer whose information is in the Vendor ID row in the/proc/cpuinfo file.
If its manufacturer is AUTHENTICAMD, it will be shown as AMD;
If its manufacturer is Genuineintel, it will be displayed as Intel Corporation;
Otherwise, it is said that it is a non-mainstream company;
#!/bin/bash
#program:
#判断主机CPU信号
#history 2016-10-21-14:43
Path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bash
Export PATH
A=authenticamd
I=genuineintel
Cpuname= ' grep-e-i ' ^vendor.*id '/proc/cpuinfo | Cut-d:-f2 | Head-1 '
if [$CPUNAME = = $A]; Then
echo "The CPU is AMD company."
elif [$CPUNAME = = $I]; Then
echo "The CPU is Intel company."
Else
echo "The CPU is not a mainstream CPU company."
Fi
Exercise Three:
Write a script:
Pass three integers to the script to determine the maximum and minimum numbers and display them.
#!/bin/bash
#program:
# Determine the size of 3 numbers, showing the minimum and maximum values
#history 2016-10-21-15:22
Path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bash
Export PATH
If [$2-ge $]; Then
Max=$2
Min=$1
Else
Max=$1
Min=$2
Fi
If [$3-gt $MAX]; Then
Max=$3
elif [$3-lt $MIN]; Then
Min=$3
Fi
echo "The MIN $MIN, the MAX $MAX"
Exercise Four:
Pass 3 parameters to the script, the parameters are the user name, the user's account information extracted
Placed in the/tmp/testusers.txt file and requires a line number at the beginning of each line.
#!/bin/bash
#program:
#传递三个参数给脚本, extract user information into/tmp/testusers.txt text
#history Donggen 2016-10-21-17:20
Path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bash
Export PATH
A= ' ID $ '
b= ' ID $ "
C= ' ID $ $ '
echo "1. $A" >>/tmp/testusers.txt
echo "2. $B" >>/tmp/testusers.txt
echo "3. $C" >>/tmp/testusers.txt
This article is from the "Learn Linux history" blog, please be sure to keep this source http://woyaoxuelinux.blog.51cto.com/5663865/1864322
Linux command exercise: Basic Bash Scripting practice taking three number maximums and minimum values