BASH:比较文件的权限

BASH:比较文件的权限,bash,shell,unix,Bash,Shell,Unix,我试图通过以下代码比较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

我试图通过以下代码比较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--
,这解释了您收到的错误消息。

如果权限相等,我只想打印权限。然后不要再调用
stat
。只需
echo$fileperm
就可以了。它成功了,谢谢,一个滴答声正朝你走来:)不应该是
#/bin/bash