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 " > i"> 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