SHELL入门学习

SHELL 入门学习

shell 变量

vim shellViable.sh

#! /bin/bash
# shell demo
string="abcd"
echo ${#string}
echo $string

echo "Sheel "
echo "$0"
echo "$1"
echo "$2"
echo "$3"

val=`expr 2 + 2`
echo "number sum:$val"
[root@alliyun cainiaoSheelScript]# chmod +x  shellViable.sh
[root@alliyun cainiaoSheelScript]# ./shellViable.sh 
4
abcd
Sheel 
./shellViable.sh



number sum:4

shell echo

vim shellEcho.sh

#! /bin/bash
# echo 
echo "It is a test"
echo It is a test

read name
echo $name It is a test

echo It is a test >myfile
[root@alliyun cainiaoSheelScript]# chmod +x shellEcho.sh
[root@alliyun cainiaoSheelScript]# ./shellEcho.sh 
It is a test
It is a test
look
look It is a test

shell printf

vim shellPrintf.sh

#! /bin/bash
# printf
echo Hello,sheel
printf Hello,sheel "\n"

printf "%-10s %-8s %-4s \n"
printf "%-10s %-8s %-4.2f \n"
printf "%-10s %-8s %-4.2f \n"
printf "%-10s %-8s %-4.2f \n"
[root@alliyun cainiaoSheelScript]# chmod +x shellPrintf.sh 
[root@alliyun cainiaoSheelScript]# ./shellPrintf.sh 
Hello,sheel
Hello,sheel                         
                    0.00 
                    0.00 
                    0.00 

shell test

vim shellTest.sh

#! /bin/bash
# sheel test
num1=100
num2=101
if test $num1 -eq $num2
then
        echo true
else
        echo false
fi

[root@alliyun cainiaoSheelScript]# chmod +x shellTest.sh
[root@alliyun cainiaoSheelScript]# ./shellTest.sh 
false

shell if then

vim shellIfThen.sh

#! /bin/bash
# if then else then

num1=100
num2=200

if [ $num1 -eq 100 ]
then
        echo num1 is 100
else
        echo num1 is not 100
fi

if  [ $num2 -eq 100 ]
then
        echo num2 is 100
elif [ $num2 -eq 200 ]
then
        echo num2 is 200
else
        echo num2 is not 200
fi
~        
[root@alliyun cainiaoSheelScript]# chmod +x shellIfThen.sh 
[root@alliyun cainiaoSheelScript]# ./shellIfThen.sh 
num1 is 100
num2 is 200

shell While

vim shellWhile.sh

#! /bin/bash
# sheel while

int=1
while (($int<=5))
do
        echo $int
        let int++
done

[root@alliyun cainiaoSheelScript]# chmod +x shellWhile.sh 
[root@alliyun cainiaoSheelScript]# ./shellWhile.sh 
1
2
3
4
5

shell function

vim shellFunction.sh

#! /bin/bash
# function
domoFun(){
        echo this is my first sheel fun!
}

echo fun start..
domoFun
echo fun end...

[root@alliyun cainiaoSheelScript]# chmod +x shellFunction.sh 
[root@alliyun cainiaoSheelScript]# ./shellFunction.sh 
fun start..
this is my first sheel fun!
fun end...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值