BASH: 比较一个文件的权限
BASH: Comparing the Permissions of a file
我尝试通过以下代码比较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: invalid option -- 'r' Try 'stat --help' for more information.
您希望这条线做什么?
echo $(stat -c '%A' "$fileperm")
对于脚本的大多数输入,$fileperm
将类似于 -rw-r--r--
,它解释了您收到的错误消息。
我尝试通过以下代码比较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: invalid option -- 'r' Try 'stat --help' for more information.
您希望这条线做什么?
echo $(stat -c '%A' "$fileperm")
对于脚本的大多数输入,$fileperm
将类似于 -rw-r--r--
,它解释了您收到的错误消息。