shell:返回文件/目录上的test值

Zen*_*net 0 bash shell

我无法检查功能测试的返回值; 男子测试对我没什么帮助.

#!/bin/bash
test=$(test -d $1)
if [ $test -eq 1 ]
then
    echo "the file exists and is a directory"
elif [ $test -eq 0 ]
    echo "file does not exist or is not a directory"
else 
    echo "error"
fi
Run Code Online (Sandbox Code Playgroud)

Ste*_*son 5

试试吧

if test -d $1
then
    echo 'the file exists and is a directory'
else
    echo 'the file doesn't exist or is not a directory'
fi
Run Code Online (Sandbox Code Playgroud)