【问题标题】:BASH: Comparing the Permissions of a fileBASH:比较文件的权限
【发布时间】:2015-03-23 22:41:06
【问题描述】:

我尝试通过以下代码比较两个文件在 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' 了解更多信息。

【问题讨论】:

  • 不应该是#!/bin/bash

标签: bash shell unix


【解决方案1】:

你希望这条线做什么?

echo $(stat -c '%A' "$fileperm") 

对于脚本的大多数输入,$fileperm 将类似于 -rw-r--r--,它解释了您收到的错误消息。

【讨论】:

  • 我只想打印权限,如果它们相等的话。
  • 那就不要再拨打stat了。只需echo $fileperm 即可。
  • 它成功了,谢谢,一个滴答声正朝你走来:)
猜你喜欢
  • 1970-01-01
  • 2013-06-06
  • 2020-09-22
  • 2013-01-26
  • 2014-11-11
  • 1970-01-01
  • 2016-03-20
  • 2014-08-24
  • 2012-09-06
相关资源
最近更新 更多