zoukankan      html  css  js  c++  java
  • shell 判断文件是否是可执行文件

    测试变量指定的文件是否存在且是可执行文件。如果存在且是可执行文件,则执行该文件,否则通过chmod命令赋予该文件可执行权限。

    //test.sh

    #!/bin/bash
    echo "enter the name:"
    read filename
    if test -x $filename ; then
    ./$filename
    else
    sudo chmod +x $filename
    ls -l $filename
    fi

      //sss.sh

    #!/bin/bash
    
    echo "What is your favourite OS?"
    select var in "Linux" "Gnu Hurd" "Free BSD" "Other"; do
      break;
    done
    echo "You have selected $var"

    运行

    ./test.sh

    输出:

    enter the name:
    sss.sh
    -rwxrwxr-x 1 f f 0 Dec  7 06:59 sss.sh

    再次运行

    ./test.sh

    输出

    enter the name:
    sss.sh
    What is your favourite OS?
    1) Linux
    2) Gnu Hurd
    3) Free BSD
    4) Other
    #? 1
    You have selected Linux

  • 相关阅读:
    vim技巧2
    vim技巧1
    网站压力测试工具
    CentOS mysql安装
    破解root
    渐进式性能监测案例
    网络监测介绍
    I/O检测介绍
    虚拟内存介绍
    @Slf4j
  • 原文地址:https://www.cnblogs.com/sea-stream/p/10085789.html
Copyright © 2011-2022 走看看