linux:shell编程的基本了解

在这里插入图片描述
shell 是用C语言编写的程序,它是用户使用Linux的桥梁。
shell既是一种命令语言,又是一种程序设计语言。shell是指一种应用程序,这个程序提供了一个界面,用户通过这个界面访问操作系统内核的服务。

示例脚本:echo ‘hello world’
在这里插入图片描述
可以创建test.sh文件,把上面脚本写进去
touch test.sh
vim test.sh
在这里插入图片描述
然后执行运行命令 ./test.sh
在这里插入图片描述
发现权限不够,分配权限再执行
在这里插入图片描述

变量
1,声明变量赋值
myname =‘zengchaot’
echo $myname
echo ${myname}
在这里插入图片描述

2,printf 格式化打印
printf “%-10s %-8s %-4s\n” 姓名 性别 体重kg
printf “%-10s %-8s %-4f\n” 郭靖 男 66.4425
printf “%-10s %-8s %-4f\n” 张三 男 66.5555
printf “%-10s %-8s %-4f\n” 黄蓉 女 33.3333
在这里插入图片描述
3,循环
1,for
语法:
for var in item1 item2 …itemN
do
command1
command1

done
案例:
for loop in 1 2 3 4 5 #loop是变量名,1-5是要遍历的数组
do
echo “the value is :” $loop
done

for str in ‘this’ ‘is’ ‘a’ ‘string’
do
echo $str
done
在这里插入图片描述

2,while循环
语法:
while condition
do
command
done
案例:
int =1
while(( $int<=5 ))
do
echo $int
let “int++”
done

死循环
语法:
while :
do
 command
done

while ture
do
command
done

for(( ; 😉)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值