在保留轉義空格的同時回顯到文件中?

在保留轉義空格的同時回顯到文件中?

如果不更新,update_history我如何確保我的文字檔案將包含:

hello\ world john\ doe

這就是我如何將$greeting $name函數或命令傳遞為hello\ world john\ doe.


function update_history {
  history=/tmp/hist
  grep -qF "$1" "$history" \
    || (combinations=$(echo "$1" | cat - $history) \
        && echo "$combinations" > $history)
}

greeting=hello\ world
name=john\ doe

update_history "$greeting $name"

答案1

將參數擴展括在雙引號中:

update_history "$greeting" "$name"

相關內容