我试图通过以下代码比较Bash中两个文件的前提:
!#/bin/bash
echo "Enter the first file name: "
read first
echo "Enter the second file name: "
read second
fileperm=$(stat -c '%A' "$first")
filepermi=$(stat -c '%A' "$second")
if [ "$fileperm" = "$filepermi" ]; then
echo $(stat -c '%A' "$fileperm")
fi
但如果以下是错误,它会给我错误:
stat:无效选项--'r'有关详细信息,请尝试'stat--help'
您希望这一行做什么?
echo $(stat -c '%A' "$fileperm")
对于脚本的大多数输入,$fileperm
将类似于-rw-r--r--
,它解释了您收到的错误消息。