4000-520-616
欢迎来到免疫在线!(蚂蚁淘生物旗下平台)  请登录 |  免费注册 |  询价篮
主营:原厂直采,平行进口,授权代理(蚂蚁淘为您服务)
咨询热线电话
4000-520-616
当前位置: 首页 > 新闻动态 >
新闻详情
Bourne外壳具有还是只有? @glennjackman Bourne外壳程序只有,它...
来自 : www.codenong.com/10319652/ 发布时间:2021-03-25
1
2
3
4
5
if -x $file then
echo File \'$file\' is executable
else
echo File \'$file\' is not executable or found
endif要确定文件类型,请尝试使用file命令。您可以解析输出以查看确切的文件类型。单词\'o警告:有时file将返回多行。这是在Mac上发生的情况:1
2
3
4
$ file /bin/ls
/bin/ls: Mach-O universal binary with 2 architectures
/bin/ls for architecture x86_64 : Mach-O 64-bit executable x86_64
/bin/ls for architecture i386 : Mach-O executable i386file命令根据操作系统返回不同的输出。但是,单词executable将出现在可执行程序中,通常该体系结构也会出现。将以上内容与我在Linux机器上获得的内容进行比较:1
2
$ file /bin/ls
/bin/ls: ELF 64-bit LSB executable, AMD x86-64, version 1 SYSV , for GNU/Linux 2.6.9, dynamically linked uses shared libs , stripped和一个Solaris框:1
2
$ file /bin/ls
/bin/ls: ELF 32-bit MSB executable SPARC Version 1, dynamically linked, stripped在这三个部分中,您都会看到单词executable和体系结构(x86-64,i386或SPARC和32-bit)。

附录

Thank you very much, that seems the way to go. Before I mark this as my answer, can you please guide me as to what kind of script shell check I would have to perform (ie, what kind of parsing) on \'file\' in order to check whether I can execute a program ? If such a test is too difficult to make on a general basis, I would at least like to check whether it\'s a linux executable or osX (Mach-O)在我的头顶上,您可以在BASH中执行以下操作:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
if -x $file file $file | grep -q Mach-O
then
echo This is an executable Mac file
elif -x $file file $file | grep -q GNU/Linux
then
echo This is an executable Linux File
elif -x $file file $file | grep q shell script
then
echo This is an executable Shell Script
elif -x $file
then
echo This file is merely marked executable, but what type is a mystery
else
echo This file isn\'t even marked as being executable
基本上,我正在运行测试,然后如果成功,则对file命令的输出执行grep。 grep -q表示不打印任何输出,而是使用grep的退出代码查看我是否找到了字符串。如果您的系统不使用grep -q,则可以尝试grep\"regex\"> /dev/null 2>&1。同样,file命令的输出可能因系统而异,因此您必须验证它们是否可以在您的系统上工作。另外,我正在检查可执行文件位。如果文件是二进制可执行文件,但可执行文件位未打开,我将说它不是可执行文件。这可能不是您想要的。

本文链接: http://testbourne.immuno-online.com/view-772438.html

发布于 : 2021-03-25 阅读(0)
公司介绍
品牌分类
其他
联络我们
服务热线:4000-520-616
(限工作日9:00-18:00)
QQ :1570468124
手机:18915418616