【发布时间】:2014-09-21 03:29:42
【问题描述】:
我正在 linux shell 中制作一个带有快速菜单的程序。
一个选项是编辑或更改目录。
我需要看看它是目录还是文件,因为我需要使用vim作为文件,使用cd作为目录。
感谢您的阅读/帮助
【问题讨论】:
-
你检查
man test
我正在 linux shell 中制作一个带有快速菜单的程序。
一个选项是编辑或更改目录。
我需要看看它是目录还是文件,因为我需要使用vim作为文件,使用cd作为目录。
感谢您的阅读/帮助
【问题讨论】:
man test
echo "Input a file: "
IFS= read -r file
if test -f "$file"
then
echo "$file is a regular file"
elif test -d "$file"
echo "$file is a directory"
else
echo "It's something else, like a socket, fifo or device."
fi
另外,如果您 cd 但在脚本退出后仍发现自己位于同一目录中,请参阅 this post。
【讨论】: