https://stackoverflow.com/questions/14505026/set-variable-in-current-shell-from-awk
Here's another way.
This is especially useful when when you've got the values of your variables in a single variable and you want split them up. For example, you have a list of values from a single row in a database that you want to create variables out of.
val="hello|beautiful|world" # assume this string comes from a database query read a b c <<< $( echo ${val} | awk -F"|" '{print $1" "$2" "$3}' ) echo $a #hello echo $b #beautiful echo $c #world
We need the 'here string' i.e <<< in this case, because the read command does not read from a pipe and instead reads from stdin
댓글