测试变量指定的文件是否存在且是可执行文件。如果存在且是可执行文件,则执行该文件,否则通过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 f f Dec : 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

shell 判断文件是否是可执行文件的更多相关文章

  1. shell判断文件是否存在

    转自:http://www.cnblogs.com/sunyubo/archive/2011/10/17/2282047.html 1. shell判断文件,目录是否存在或者具有权限 2. #!/bi ...

  2. Linux shell判断文件和文件夹是否存在

    shell判断文件,目录是否存在或者具有权限 #!/bin/sh myPath="/var/log/httpd/" myFile="/var /log/httpd/acc ...

  3. shell 判断文件、目录是否存在

    shell判断文件是否存在   1. shell判断文件,目录是否存在或者具有权限 2. #!/bin/sh 3. 4. myPath="/var/log/httpd/" 5. m ...

  4. Shell 判断文件或文件夹是否存在

    #shell判断文件夹是否存在 #如果文件夹不存在,创建文件夹 if [ ! -d "/myfolder" ]; then mkdir /myfolder fi #shell判断文 ...

  5. [转] Linux shell判断文件和文件夹是否存在

    shell判断文件,目录是否存在或者具有权限 #!/bin/sh myPath="/var/log/httpd/" myFile="/var /log/httpd/acc ...

  6. shell判断文件夹是否存在

    #shell判断文件夹是否存在 #如果文件夹不存在,创建文件夹 if [ ! -d "/myfolder" ]; then mkdir /myfolder fi #shell判断文 ...

  7. shell判断文件类型和权限

    shell  判断文件类型. -d 文件 判断该文件是否存在,并且是否为目录(是目录为真) -e文件 判断该文件是否存在(存在为真) -f文件 判断该文件是否存在,并且是否为文件(是普通文件为真) - ...

  8. shell判断文件是否存在[转]

    原文出处: http://canofy.iteye.com/blog/252289 shell判断文件,目录是否存在或者具有权限 #!/bin/sh myPath="/var/log/htt ...

  9. shell判断文件,目录是否存在或者具有权限

    shell判断文件,目录是否存在或者具有权限  #!/bin/sh  myPath="/var/log/httpd/"  myFile="/var /log/httpd/ ...

随机推荐

  1. go http 文件下载

    package main import ( "fmt" "net/http" "os" ) func DownFile() { userFi ...

  2. interface Impl

    public interface ActionBarOperations { void initSthOne(); void initSthTwo(); } public class ActionBa ...

  3. java如何使用base64生成图片文件

    import org.apache.commons.codec.binary.Base64; public static void decodeFile(String base64Str,File f ...

  4. OneThink视图模型进行组合查询!文档组合文档详情

    测试方法:twoCate: public function twoCate(){ $where = array( 'category_id'=>43 ); $list = D('TwoView' ...

  5. 无向连通图求割点(tarjan算法去掉改割点剩下的联通分量数目)

    poj2117 Electricity Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3603   Accepted: 12 ...

  6. nginx配置文件内容详情及基本属性配置

    Nginx的配置文件nginx.conf配置详解如下: user nginx nginx ; Nginx用户及组:用户 组.window下不指定 worker_processes 8; 工作进程:数目 ...

  7. 模反元素 RSA Euler's totient function

    https://baike.baidu.com/item/模反元素/20417595 如果两个正整数a和n互质,那么一定可以找到整数b,使得 ab-1 被n整除,或者说ab被n除的余数是1.这时,b就 ...

  8. Django - rest - framework - 上

    一.快速实例 http://www.django-rest-framework.org/tutorial/quickstart/#quickstart http://www.cnblogs.com/y ...

  9. EA类图与代码同步

    画了一段时间的图,愈发感觉到EA是一个强大的软件,而不不过一个绘图工具那么简单. . 随着学习时间的延长.如今写程序并不能像曾经一样随心所欲,想到什么就敲什么了,而是要先绘图(也就是理需求和思路的过程 ...

  10. Worst Performing Queries

    WITH TMP AS ( SELECT TOP 100 CAST(SUM(s.total_elapsed_time) / 1000000.0 AS DECIMAL(10, 2)) AS [Total ...