|
#!/bin/bash
if [ -x "$filename" ]; then
echo "File $filename exists."; cp $filename $filename.bak
else
echo "File $filename not found."; touch $filename
fi; echo "File test complete."
其中的 if [ -x "$filename" ]; then 有这样的语法吗?特别是-x参数什么意思,我模仿着弄了个例子:
#!/bin/bash
if [ -x "$wang" ];then
echo "File $wang exists.";cp $wang $wang.bak
else
echo "File $wang not found.";touch $wang
fi;echo "File test complete."
其中wang这个文件是存在的,没能够正确执行。显示如下:
File not found.
touch: 缺少了文件操作数
请尝试执行“touch --help”来获取更多信息。
File test complete.
把touch $wang 改成touch wang 执行结果如下:
File not found.
File test complete.
明明wang这个文件存在呀,我怀疑if [ -x "$wang" ];then是不是有问题,恭请高手指点一下我这个菜鸟,谢谢! |
|