linux-shell编程笔记01

时间:2024-07-12 12:06:26

==============常用命令

env
echo $path
export
-------------
cp
mv
mkdir
rm
-------------
cd
ls
ll
-------------
more
cat
tail
vi
-------------
ifconfig
getconf LONG_BIT
df -h

==============shell语法

#!/bin/bash
#test1
echo "Hello shell"
echo `who`
echo "who"
-----------------------
#!/bin/bash
#t2
echo "test 2"
var1=
var2=
let var3=$var2+$var1
echo $var3
echo "end!"
-----------------------
#!/bin/bash
#t3
echo "test 3"
echo "input first integer please:"
read var1
echo "input second integer please:"
read var2
let var3=var2+var1
echo $var1+$var2=$var3
echo "end!"
-----------------------
#!/bin/bash
#t4
echo "test 4"
var1=$
if [ $var1 -lt ]
then
echo "illegal!"
fi
echo "end!"
-----------------------
#!/bin/bash
#t5
echo "test 5"
var1=$
if [ $var1 -lt ]
then
echo "illegal!"
else
echo "Yeah!"
fi
echo "end!" -----------------------
#!/bin/bash
#t6
echo "test 6"
var1=$
if [ $var1 -lt ]
then
echo "illegal!"
elif [ $var1 -lt ]
then
echo "fail!"
else
echo "Yeah!"
fi
echo "end!" -----------------------
#!/bin/bash sum=
for ((i=;i<;i++))
{
let "sum+=i"
}
echo "sum=$sum" -----------------------
#!/bin/bash for animal in cat dog pig duck mice
do
echo $animal
done -----------------------
#!/bin/bash sum=
echo "input your number:"
read num while(($num>))
do
let "sum+=num"
let "num--"
done echo "sum=$sum"