/bin/bashfor File in $(ls)do # extract the file extension Extension=${File##*.} case "$Extension" in sh) echo " Shell script: $File" ;; md) echo " Markdown file: $File" ;; png) echo "PNG image file: $File" ;; *) echo "Unknown: $Fi...
for File in $(ls) do # extract the file extension Extension=${File##*.} case "$Extension" in sh) echo " Shell script: $File" ;; md) echo " Markdown file: $File" ;; png) echo "PNG image file: $File" ;; *) echo "Unknown: $File" ;; esac done 将此文本保存到名为“filety...
Multiple patterns can be used in a single clause, making the script more concise and efficient. Digits or numerical variables can also be used in case statements. Bash case statements are powerful yet easy to write. When you revisit an old Linux script you'll be glad you used a case state...
/bin/bash># This script is a value test for 1 and 2>#2016-0828 author chawan>#>if[1-lt2];then>echo"2 is bigger">fi>EOF[root@localhost test]# chmod +x if11[root@localhost test]# ./if112is bigger 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. ……… if双分支语句 双...
在局域网环境中工作,经常要访问别人的电脑,而他们大多还在使用windows,所以要反复的mount、umount共享目录,烦死了,并且不umount还不行,别人一关机,这边再操作就要停顿半天没反应。所以编写了一个小小的shell script,简化这些工作。代码、注释和说明都在一起了,应该不用再多解释了吧。
1、如是start,那么创建/var/lock/subsys/script.sh,显示启动成功; 2、如果参数是stop,则删除/var/lock/subsys/script.sh,显示停止成功 3、如果restart,则删除,再创建,显示成功; 4、如果status, 如果文件存在,则显示running,否则,显示stopped #!/bin/bash ...
其它任何参数:则显示“script.sh {start|stop|restart|status}” 现在将if语句改成case语句: [root@localhost tutor]# vim service_case.sh #!/bin/bash#SvcName=`basename$0`LockFile=/var/lock/subsys/$SvcNameif[$#-lt1];thenecho"Usage:`basename$0`{start|restart|stop|status}"exit5ficase$1instart)...
/bin/bash #chkconfig: - 50 50 #description: test service script prog=$(basename $0) lockfile=/var/lock/subsys/$prog case $1 in start) if [ -f $lockfile ];then echo "$prog is running yet" else touch $lcokfile [ $? -eq 0 ] && echo "start $rpog finished"...
/bin/bash## chkconfig: - 50 50 注:定义运行级别、启动优先级、关闭优先级# description: test service script 注:描述信息#prog=$(basename$0)注:以变量替换的方式取路径基名,并赋值给变量proglockfile=/var/lock/subsys/$prog注:给变量lockfile赋值一个文件路径case$1instart)if[-f$lockfile];then注:-f...
下面脚本里第三选择想实现返回echo"选择yes/no",用了whiletrue;do,retrun0虽然能实现功能,但是一直报错return:canonly`return'fromafunctionorsourcedscript,help!!! #!/bin/bash echo"选择yes/no" readchooise case$chooisein yes) echo"1111" ;; no) exit0 ;; *) echo"重新选择" ;; esac...