shell的用法

shell文件都是以 .sh 结尾

#! /bin/sh //这里要写绝对路径
或者 #! /bin/bush
h=“hello123” #变量赋值
echo “hello”
echo ${h};
echo $h
echo “this is shell” > hello.txt

注释:需要修改权限才能执行 chmod u+x hello.sh

case的用法
while.c
include"stdio.h"
int main()
{
while(1);
return 0;
}

case.sh
#! /bin/sh
case "KaTeX parse error: Expected 'EOF', got '#' at position 71: … #̲引用
start) echo “启动程序”
/home/study/10.21/while & #&后台运行
;;
stop)echo “停止程序”
pid=ps -elf | grep while | grep -v 'grep' | awk '{print $4}' #提取进程号
kill -9 $pid
;;
restart)
pid=ps -elf | grep while | grep -v 'grep' | awk '{print $4}'
kill -9 $pid
/home/study/10.21/while &
;;
status)
pid=ps -elf | grep while | grep -v 'grep' | awk '{print $4}'
if [ -z $pid ]; then #pid 为空则成立 [ -z 数值 ] 如果数值为空则成立
echo “程序未启动”

for循环的用法
#for((i=0;i<3;i++))
#do

useradd $i

cd /home/$i

echo "this is i &quot; &gt; i&quot;&gt; i">i.txt

#done

for user in 0 1 2
do
userdel -r $user
done

if的用法
if.sh
#! /bin/sh
if [ -d $1 ];then #判断,是目录则成立
echo “是一个目录”
elif [ -f $1 ];then #判断,是文件则成了
echo “是一个文件”
fi

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值