测试文件的目录是否在BASH脚本中写作



我正在尝试检查以查看文件的目录是否可写。

fullPATH=$(realpath "$1")
echo "realpath => $fullPATH"
pathDIR=${fullPATH%/*}
echo "pathDIR => $pathDIR"
if [ ! -w "$pathDIR" ]; then
    echo $1 is a file in a directory that is not writeable.
#   return 1
else
    echo writable
fi

我敢肯定,我在格式化Pathdir的路径方面将事情弄乱了,但我不知道该怎么办。

如果语句您必须US $ fullPath

if [ ! -w "$fullPATH" ]

尝试

    # /bin/bash
fullPATH=$(realpath "$1")
echo "realpath => $fullPATH"
pathDIR=${fullPATH%/*}
echo "pathDIR => $fullPATH"
if [ ! -w "$fullPATH" ]
 then
    echo $1 is a file in a directory that is not writeable.
#   return 1
else
    echo writable
fi

最新更新