如何将以下命令设为变量?我的意思是我需要将此命令分配给变量以便在 for 循环中使用它。
for i in $(sed 's|/home/bssuser/Scripts/Amany/log/bssuser/CDR/Postpaid_CDR_Log/||' /home/bssuser/Scripts/Amany/logs.csv )
我有一个文件名为 start,路径如下:
/home/bssuser/Scripts/Amany/log/bssuser/CDR/Postpaid_CDR_Log
我需要删除所有这些
答案1
var1="$(for i in $(sed 's|/home/bssuser/Scripts/Amany/log/bssuser/CDR/Postpaid_CDR_Log/||' /home/bssuser/Scripts/Amany/logs.csv ))"
答案2
如何将
sed
命令的输出作为变量?如何将以下命令设为变量?我的意思是我需要将此命令分配给变量以便在 for 循环中使用它。
对于 $(sed 's|/home/bssuser/Scripts/Amany/log/bssuser/CDR/Postpaid_CDR_Log/||' /home/bssuser/Scripts/Amany/logs.csv ) 中的 i
您的意思是循环读取每行输出到变量中吗?如果是这样,那么您可以使用Bash 的进程替换使用while
如下循环:
while IFS= read -r line
do
# Do whatever you want with the line
echo "$line"
done < <(sed 's|/home/bssuser/Scripts/Amany/log/bssuser/CDR/Postpaid_CDR_Log/||' /home/bssuser/Scripts/Amany/logs.csv)
也可以通过将输出传送到循环来完成,如下所示:
sed 's|/home/bssuser/Scripts/Amany/log/bssuser/CDR/Postpaid_CDR_Log/||' /home/bssuser/Scripts/Amany/logs.csv |
while IFS= read -r line
do
# Do whatever you want with the line
echo "$line"
done