我正在尝试逐行阅读以下文件以进行以下列出的操作
- 单独提取目录并为其分配一个变量
- 提取该行中可用的权限,并在权限之间添加逗号并分配给另一个变量
- 最后应用setfacl逻辑,如输出所示。
文件-bkp.txt
# file: /disk1/script_1/ user::rwx group::r-x group:service:r-x mask::r-x other::r-x
# file: /disk1/script_1//hello.txt user::rw- group::r-- other::r--
# file: /disk1/script_1//bkp_10.txt user::rwx group::r-x other::r-x
我的代码
#!/bin/sh
input="bkp.txt"
while IFS= read -r line;
do
echo $line
file_name=`sed -e 's/# file:\(.*\)/\1/g' "$line" | awk '{print $1}'`
echo $file_name
file_perm=`sed -e 's/# file:\(.*\)/\1/g' "$line" | awk '{$1=""}{print}' | tr ' ' ',' | awk
'{sub(",","")}1'`
echo $file_perm
echo "setfacl -m "$file_perm" "$file_name" executing"
done <"$input"
必需的输出
setfacl -m user::rwx,group::r-x,group:service:r-x,mask::r-x,other::r-x /disk1/script_1/
setfacl -m user::rw-,group::r--,other::r-- /disk1/script_1//hello.txt
setfacl -m user::rwx,other::r-x /disk1/script_1//bkp_10.txt
但以以下错误结尾
sed: can't read # file: /disk1/script_1/ user::rwx group::r-x group:service:r-x mask::r-x
other::r-x: No such file or directory