Echo zsh:将斜杠放在括号之前

Echo zsh:将斜杠放在括号之前,echo,special-characters,zsh,Echo,Special Characters,Zsh,我需要缓存文件中的字符串,以便稍后进行grep搜索。该字符串在括号前有一个斜杠。在我抓取字符串并在壳中回音后,它的行为符合我的预期;但在我的脚本中,它删除了斜杠 下面有很多文本,但字符串中重要的部分是“(remainingTime)” 文件中的行: "session_will_expire_message" = "User session will expire in \(remainingTime). Please sign in again to avoid expiration in th

我需要缓存文件中的字符串,以便稍后进行grep搜索。该字符串在括号前有一个斜杠。在我抓取字符串并在壳中回音后,它的行为符合我的预期;但在我的脚本中,它删除了斜杠

下面有很多文本,但字符串中重要的部分是“(remainingTime)”

文件中的行:

"session_will_expire_message" = "User session will expire in \(remainingTime). Please sign in again to avoid expiration in the middle of the transaction.";
Shell命令(按预期工作):

脚本(未按预期工作):

读行时
;做
如果[[$(echo$行| grep-c“=”)-gt 0];然后
key=“$(echo$行| cut-d”“-f1 | cut-d”=“-f1 | tr-d”)”
val=“$(echo-E-$行|切-d””-f1 |切-d”=“-f2-”
/* !!--> */ [[$IS_VERBOSE==“TRUE”]&&echo“key:$key”&&echo-E-“value:${val}”
/* !!--> */ [[$key!=”&&&“${val}”!=”]&&LOCALIZED_对[$key]=“${val}”
fi

完成<$LOCALIZED_DICT#您有许多不必要的额外进程。除此之外,使用
-r
选项可防止
read
处理输入中的任何反斜杠

while IFS== read -r key val; do
    [[ -z $key || -z $val ]] && continue
    if [[ $IS_VERBOSE == TRUE ]]; then
        print -r "key: $key"
        print -r "value: $val"
    fi
    LOCALIZED_PAIR[$key]=$val
done < "$LOCALIZED_DICT"
而IFS==read-r key val;做
[[-z$key | |-z$val]]&继续(&C)
如果[[$IS_VERBOSE==TRUE]];然后
打印-r“键:$key”
打印-r“值:$val”
fi
本地化的\u对[$key]=$val
已完成<“$LOCALIZED_DICT”

顺便说一句,我喜欢guard语句逻辑,不过我可能会在Echot尝试在脚本中使用它之后设置它。由于剥离格式,该值失败很多,但这是意料之中的。不幸的是,这段代码与那行代码有相同的问题。我忘记了键选项。当我添加“-r”选项时,斜杠仍然被去掉。我认为这是唯一的改变。斜杠仍然存在(使用
declare-pval
echo“$val”
)检查)<代码>打印
本身(TIL)正在使用它。它使用
-r
选项来防止这种情况。
while read line; do
    if [[ $(echo $line | grep -c "=") -gt 0 ]]; then
        key="$(echo $line | cut -d";" -f1 | cut -d"=" -f1 | tr -d " ")"
        val="$(echo -E - $line | cut -d";" -f1 | cut -d"=" -f2-)"
/* !!--> */ [[ $IS_VERBOSE == "TRUE" ]] && echo "key: $key" && echo -E - "value: ${val}"                
/* !!--> */ [[ $key != "" && "${val}" != "" ]] && LOCALIZED_PAIR[$key]="${val}"
    fi
done < $LOCALIZED_DICT   # <-- This is an URI for .strings file
% while read l; do echo $l; done < ~/Desktop/tmpOutput 
"User session will expire in (remainingTime). Please sign in again to avoid expiration in the middle of the transaction.";
while IFS== read -r key val; do
    [[ -z $key || -z $val ]] && continue
    if [[ $IS_VERBOSE == TRUE ]]; then
        print -r "key: $key"
        print -r "value: $val"
    fi
    LOCALIZED_PAIR[$key]=$val
done < "$LOCALIZED_DICT"