我想检查Android上是否存在一个目录。
从在shell脚本中使用通配符检查文件是否存在的答案中,我得到了一个想法。所以我像下面这样使用ADB。
if [ adb shell ls ${test_dir} 2> /dev/null ] ;
then
echo "files exist"
else
echo "files do not exist"
fi
我是一名新手Bash脚本编写者。我知道
adb shell ls
将返回所有文件名,但是2> /dev/null
的含义是什么?我只关心
文件不存在
这种情况。那么我该如何反转这个条件?
第二版本
if [ ! adb shell ls ${test_dir} 2> /dev/null ] ;
then
echo "files exist"
else
echo "files do not exist"
fi
添加 !
对我无效。
/dev/null
(位桶) 使用if [ ! .... ]
进行反转 - David C. Rankin