linux - 绕过 "-"在 bash 中作为算术运算符处理

标签 linux bash operators

#!/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 $permission'

提前致谢!

最佳答案

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

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

关于linux - 绕过 "-"在 bash 中作为算术运算符处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55062133/

相关文章:

linux - tar 目录,但不要在存档中存储完整的绝对路径

macos - 在 Package Maker 安装程序 postflight 脚本期间将应用程序添加到 OSX "Login Items"

bash - 简化 bash 脚本?

python - 有什么方法可以使这个 if 语句更短更清晰吗?

linux - `gcloud compute copy-files` : permission denied when copying files

linux - 可以使用 kmalloc() 分配的最大大小是否取决于 free_area[] 的大小?

php - (x && y || z) 和 (x AND y OR z) 之间的区别

c# - 为什么 ? : operator does not work with nullable<int> assignation?

linux - shell脚本比较两个文件并将差异写入第三个文件

linux - 在 bash 中用 - 分隔符拆分字符串?