Linux in shell scripts
Stream: flow created by redirecting an input connected to the output
0: Input <
1: standard output>
2: Error Output
ls // aabb 1> test 2> & 1: standard output and standard error file to the test output redirection
>覆盖 >>追加
read aa << AABB end when faced with AABB
Note: read line feed sensitive, can only read the first row
#variable
$ Is to get the value of a variable in Linux
$?
[Root @ root ~] # [9 -ne 9]
[root @ root ~] # echo $?
1
Small script exercises
Enter a number (use the switch) "" "" "
#!/bin/bash
while :
do
echo "输入1-4的数字"
echo '你输入的数字为'
read num
case $num in
1) echo '你选择了1'
;;
2) echo '你选择了2'
;;
3) echo '你选择了3'
;;
4) echo '你选择了4'
;;
*)echo "输入有误"
continue
;;
esac
done
- 1-10 print cycle a value of 3 will be replaced hello world 3
for ((i=1;i<=10;i++))
do
if [ $i -eq 3 ]
then
echo "hello world"
else
echo "$i"
fi
done
Achieved within 10 factorial
factorial=1
for i in `seq 10`
do
factorial=`expr $factorial \* $i`
done
echo "10! = $factorial"
方法二:---------------------------------------------
num=1
for((j=1;j<=10;j++))
do
num=$((num=num*j))
done
echo "10的阶乘是$num"
Accumulated number of less than 100
#!/bin/bash
sum=0
for((i=1;i<=100;i++))
do
sum=$((sum=sum+i))
done
echo "$sum"
Multiplication table
#!/bin/bash
for((i=1;i<=9;i++))
do
for((j=1;j<=i;j++))
do
echo -n " $i*$j=`expr $i \* $j`"
done
echo " "
done
==========================================================================
Determining if the random number plus
while [ 1 ]
do
echo "请猜一个100以内数字:"
read a
b=$(( $RANDOM % 100 ))
if [$a -eq $b ]
then
echo "$b"
echo "猜对了"
elif [ $a -gt $b]
then
echo "$b"
echo "猜大了"
else
echo "$b"
echo "猜小了"
fi
done
Small note:
================================================== =
printing process tree and write to abc.file file and view the contents of the file abc.file
pstree >> abc.file
modify the file permissions for all users have the highest authority,
chmod 777
Dhcp 自动分配IP:
===================================================================
Bin "" "" "To own
ε≡9 (1> ₃ <) 6 as one to learn
*: ஐ 9 (1'ᵕ`) 6 ஐ: * I learn progress
* ✧⁺˚⁺ପ (1 · ω ·) 7 ु⁾⁾ we have learned
(ーωー) ⊃⌒ only greetings 10086
(* ❦ω❦) (* ❦ω❦) (* ❦ω❦) (* ❦ω❦) (* ❦ω ❦)