首页 > 解决方案 > shell中IF语句中两个变量之间的正斜杠是什么意思?

问题描述

我想了解这里两个变量之间的正斜杠是做什么的?

“${lsof_line/$c2}”

下面是上下文。(c2_iocs 是一个文本文件)

lsof_output=$(lsof -i)
for lsof_line in ${lsof_output}; do
    for c2 in "${c2_iocs[@]}"; do
        # echo "$lsof_line - $c2"
        if [ "${lsof_line/$c2}" != "$lsof_line" ]; then
            log warning "[!] C2 server found in lsof output SERVER: $c2 LSOF_LINE: $lsof_line"
        fi
    done
done

标签: bashshellif-statement

解决方案


这是一个字符串替换操作。当没有提供替换文本时,/以下模式是可选的。${lsof_line/$c2}相当于, 并且都删除了from${lsof_line/$c2/}中包含的字符串。$c2$lsof_line


推荐阅读