美文网首页
shell脚本实现快速解析文件

shell脚本实现快速解析文件

作者: Vvpl | 来源:发表于2016-10-26 22:00 被阅读111次

    在学习shell脚本可以轻松实现简化我们在编程过程中的复杂操作.
    下面是mygcc的代码:

    value=$1 value1="${value:0-2}" filestyle=".c" if [ $# -eq 1 ] then if [ $value1 == $filestyle ] then if [ -e $1 ] then if [ -f $1 ] then if [ -e ./a.out ] then rm ./a.out fi gcc $1 if [ -e ./a.out ] then ./a.out fi fi else echo "$1 :not such file or directory" fi else echo "$1 not .c file" fi elif [ $# -eq 0 ] then echo "which file to be edited?" else echo "error:too many arguments." fi

    此shell脚本的实现的伪代码:

    1. 判断文件的个数
    • 判断文件是否是'.c'类型的文件;
    • 判断文件是否存在;
    • 文件如果存在是否是普通文件
    • 判断./a.out文件是否存在
    • 如果存在的话就删除掉
    • 然后gcc 文件名
    • 判断./a.out文件存在,一旦存在就可以执行./a.out

    相关文章

      网友评论

          本文标题:shell脚本实现快速解析文件

          本文链接:https://www.haomeiwen.com/subject/mfrjuttx.html