bash - Awk dealing with variables containing whitespace -


i want pass string whitespaces variable awk bash script, independent of how escape it, awk complain. please consider following example:

list1:

one 2 3 4 

the output:

[user@actual ~]$ ./dator.sh list1 1470054866 2 (...) 

a working script:

cmd='awk' date=$(date +%s) variables="-v time=$date" script='nr>=2 {printf "%s %s\n", time, $1;}'  $cmd $variables "$script" $1 

and changing date-formatting break it:

cmd='awk' date=$(date -u) variables="-v time=$date" script='nr>=2 {printf "%s %s\n", time, $1;}'  $cmd $variables "$script" $1 

how should escape it?

  • every kind of quoting i'm aware of doesn't work.
  • translating , inserting escaping "\" before whitespace doesn't make difference.
  • printing variable via function suggested in solution didn't work.

arrays designed storing arbitrary arguments.

current_date=$(date +%u) variables=( -v "time=$current_date") script='nr >= 2 {printf "%s %s\n", time, $1;}' awk "${variables[@]}" "$script" "$1" 

Comments