0

Without updating update_history how can I ensure my text file will contain:

hello\ world john\ doe

That is how can I pass $greeting $name to a function or command as 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"
Philip Kirkbride
  • 9,816
  • 25
  • 95
  • 167

1 Answers1

2

Enclose the parameter expansions in double quotes:

update_history "$greeting" "$name"
Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
saga
  • 1,381
  • 11
  • 36