我发现这个bash脚本(它工作)。这个脚本起着重要的作用。脚本的整个代码质量很好。我只是想知道下面的建设是否有意义?bash if语句
if [ "${G_FILE}" != "" ] && [ -f "${G_FILE}" ] && [ -r "${G_FILE}" ]; then
....
手册上说:
[ -f FILE ] True if FILE exists and is a regular file.
[ -r FILE ] True if FILE exists and is readable.
[ STRING1 != STRING2 ] True if the strings are not equal.
我的想法:
[ -n "${G_FILE}" ]
或[ "${G_FILE}" ]
应该不是[ "${G_FILE}" != "" ]
。- 只有
[ -r "${G_FILE}" ]
也会这样做。
对吗?
的确,没有'-f',目录也会通过。 – Noctua
谢谢你的快速和良好的答案! – idobr
我会保持-f和-r。 – idobr