测试变量指定的文件是否存在且是可执行文件。如果存在且是可执行文件,则执行该文件,否则通过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. 不同linux下两网卡绑定方法

    记得原来在做性能测试时,为了提高网络吞吐率.必须将两个网卡绑定一起工作.绑定方法如下: 一.CentOS 配置   1.编辑虚拟网络接口配置文件,指定网卡IP: # vi /etc/sysconfig ...

  2. SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase, Hana]

    Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-co ...

  3. pandas读取保存数据

    将本人使用过的一些操作记录下来 1.读取数据,使用:data = pd.read_csv('./data/file.csv') 2.数据处理,如果你要修改某一个数据,其实把DATAFRAME数据看做是 ...

  4. HDU_5521_Meeting

    Meeting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  5. Mybatis解决sql中like通配符模糊匹配 构造方法覆盖 mybits 增删改

    <select id="getRecByNameWildcard" parameterType="Student" resultMap="res ...

  6. 什么是Java序列化和反序列化,如何实现Java序列化

    1.概念 序列化:把Java对象转换为字节序列的过程. 反序列化:把字节序列恢复为Java对象的过程. 2.用途 对象的序列化主要有两种用途: 1) 把对象的字节序列永久地保存到硬盘上,通常存放在一个 ...

  7. ios 开发failed to chmod

    当XCode遇到此问题的时候,可通过重启模拟器和XCode来解决 http://www.jianshu.com/p/f8e7c5949660 合并分支, xcode报错  couldn't load ...

  8. Django - 常用配置

    一.logging配置 Django项目常用的logging配置 settings.py LOGGING = { 'version': 1, 'disable_existing_loggers': F ...

  9. SNMP 原理及配置简述 net-snmp-utils net-snmp 第2版基于SNMP 群体名(community name) 第3版引入了安全性更高的访问控制方法 SNMP协议操作只有4种 Apache的php_snmp 模块

    SNMP 原理及配置简述  net-snmp-utils  net-snmp 第2版基于SNMP 群体名(community name) 第3版引入了安全性更高的访问控制方法 SNMP协议操作只有4种 ...

  10. 002-线程实现方式【thread、runnable、callale、thread和runnable对比】

    一.概述 1.实现方式 在java中对于多线程实现一定要有一个线程的主类,而这个线程的主类往往是需要操作一些资源,但是对于多线程主类的实现是: 继承Thread父类 从java的Thread类继承实现 ...