エスケープされたスペースを維持しながらファイルにエコーしますか?

エスケープされたスペースを維持しながらファイルにエコーしますか?

更新せずに、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"

関連情報