shell脚本快速入门

shell脚本快速入门

前言
编程语言的入门都有一些相通之处,这也是为什么精通一门编程语言的人,在接触一种新语言的时候,能够迅速上手。下面讲下shell入门的几个demo,帮助你迅速上手shell。
1 变量相关

#!/bin/bash
name="helloworld"
name="lilming"
#readonly name="read only"
#unset name
myname='liming'
var="my name is ${myname}"
echo ${var}
echo ${myname}
echo ${name}

2 数组的使用

#!/bin/bash
name="helloworld"
name="liming"
: '
#length is 15
name="this is"" my name" 
#name="this is my name"
#echo ${var}
#echo ${myname}
# cut strings
#echo ${name:1:4}
echo ${name:2:10}
echo ${#name}
'
array_name=(li wang xiang zhang)
array_para[0]="w"; array_para[3]="s"
echo ${array_name[1]}
echo ${array_para[3]}
# echo array all elements
echo ${array_name[@]}
echo ${#array_name[@]}
echo ${#array_name[0]}
echo ${#array_para[1]}

3 打印相关

#!/bin/bash
printf "hello\n"
printf " %d, %f\n" 15 15.0000

4 运算相关

#!/bin/bash
a=10
b="abc"
c="10"
d="20"
# -eq -ne -gt -lt -ge -le 
if [ $a != 10 ]
then 
	echo " a is not 10 "
else
       	echo " a is  10 "
fi
if [ $c -eq 20 -a $d -eq 20 ]
then 
	echo " a ,b all right "
else
       	echo " a ,b all wrong "
fi
: '
if [ $c20 ]
then 
	echo " a ,b all right "
else
       	echo " a ,b all wrong "
fi
'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值