bash编程之 第六课作业
来源:互联网 发布:上海跳跃网络 编辑:程序博客网 时间:2024/06/02 09:05
1、脚本使用格式:
mkscript.sh [-D|--description "script description"] [-A|--author "script author"] 文件名
2、如果文件事先不存在,则创建;且前几行内容如下所示:
#!/bin/bash
# Description: script description
# Author: script author
#
3、如果文件事先存在,但不空,且第一行不是“#!/bin/bash”,则提示语法错误并退出;如果第一行是“#!/bin/bash”,则使用vim打开脚本;把光标直接定位至最后一行
4、打开脚本后关闭时判断脚本是否有语法错误如果有,提示输入y继续编辑,输入n放弃并退出;如果没有,则给此文件以执行权限;
#!/bin/bash#a1=$1a2=$2a3=$3a4=$4a5=$5desc=""if [ $1 == "-D" -o $1 == "--description" ];then desc=$2elif [ $3 == "-D" -o $3 == "--description" ];then desc=$4fiif [ $# -eq 1 ];then filename=$1elif [ $# -eq 3 ];then filename=$3elif [ $# -eq 5 ];then filename=$5else echo 'please use format: mkscript.sh [-D|--description "script description"] [-A|--author "script author"] filename' exit 1fiecho "desc=$desc"echo "author=$author"echo "filename=$filename"if ! [ -f $filename ]; then touch $filename echo "#!/bin/bash" >> $filename echo "# Description: $desc" >> $filename echo "# Author: $author" >> $filename echo "#" >> $filenameelif [ -s $filename ]; then str=`grep -n "^#\!/bin/bash$" $filename` str2=${str%:*} #find the line_number of #\!/bin/bash if [ $str2 -ne 1 ]; then echo "the first line of $filename is not #\!/bin/bash" exit 2 else vi + $filename trap "myquit" 1 2 3 15 fifimyquit(){ bash -n $filename &> /dev/null if [ $? -eq 0 ]; then chmod +x $filename else read -p 'there is something wrong, continue to edit ? y/n : ' yesOrNo if [ $yesOrNo == "n" ]; then exit 0 fi fi}
阅读全文
0 0
- bash编程之 第六课作业
- 第六次编程作业
- BASH脚本第六课
- BASH第八课作业
- BASH脚本第六课-2
- 计算机网络课第六次作业之CDMA习题
- 【bash】编程之常用命令
- bash编程之数组
- bash编程之 数组
- bash编程之 函数
- 通信网络编程第六次作业
- 【bash】bash脚本编程之条件判断
- bash参考手册之七(作业控制)
- 【bash】编程之函数function
- bash脚本编程之选项
- bash编程之${ }用法总结
- Shell编程之Bash变量
- bash编程之 条件判断
- bash编程之 函数
- React context/contextTypes
- idhttp解决中文乱码问题
- bash编程之 字符串操作
- MVC
- bash编程之 第六课作业
- Android总结篇系列:Android广播机制
- bash编程之 find文件查找工具
- C++ STL函数详解
- bash编程之 crontab 定时任务
- Hbase counter计数器
- 使用 iconv 自动判断文件编码
- 总价,净价,有效价
- Core Bluetooth框架之一:Central与Peripheral