如果不更新,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"