【问题标题】:Bypass "-" processing as arithmetic operator in bash绕过“-”处理作为bash中的算术运算符
【发布时间】:2019-03-08 11:18:34
【问题描述】:
#!/bin/bash

dir=$1
cd $dir
list=$(find . -maxdepth 1 -mindepth 1 -type d -printf '%f,')
IFS=',' read -a array <<< "${list}"
for i in "${array[@]}"
do
longPermission=$(getfacl $i |stat -c %A $i)
longOwner=$(getfacl $i |grep owner)

ownerPermission=${longPermission:1:3}
owner=${longOwner:9}
if (($ownerPermission=="rwx"))
then
    permission='FULL_PERMISSION'
fi

if (($ownerPermission=="rw-"))
then
    permission='READ/WRITE_PERMISSION'
fi

#if (($ownerPermission=="r--"))
#then
#   permission='READ_ONLY_PERMISSION'
#fi

echo ’BUERO\ $owner -user -group -type windows permission $permission’

done

Bash 将 rw- 和 rw-- 中的“-”视为算术运算符,但我想要实现的是将其处理为字符串,因为我想处理从 getfacl $i |grep owner 获得的输出,它给了我回报我想在

中回显的字符串

echo 'BUERO\ $owner -user -group -type windows 权限$permission'

提前致谢!

【问题讨论】:

    标签: linux bash operators


    【解决方案1】:

    使用if [[ $ownerPermission == "rwx" ]]if [[ $ownerPermission == "rw-" ]]

    (( expr )) 用于算术表达式,此处不需要。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-17
      • 2015-10-15
      • 2018-09-23
      • 1970-01-01
      • 2019-04-16
      • 1970-01-01
      • 2022-01-07
      相关资源
      最近更新 更多