不知道这个方法是否适用。
#!/bin/bash
file=$1
if [[ -x "$file" ]]
then
if [ $? = 0 ]
then
echo $file is executable
else
echo $file is not executable
fi
fi
但是如果我使用非可执行文件运行此脚本,它不会返回任何内容 但是,如果我使用可执行文件运行此脚本,它将返回“名称可执行”
block 引用>just want to know about positional parameter working. i'm a beginner.but can i take the output of the first if condition into $?
最佳答案
对于这样的测试,您不需要内部 if。此代码将完成这项工作:
#!/bin/bash
file=$1
if [[ -x "$file" ]]
then
echo $file is executable
else
echo $file is not executable
fi
关于linux - 如何从 if 条件中获取输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60595870/