Trying to do so
echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'
But it doesn't work
Trying to do so
echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'
But it doesn't work
You are passing them into a subshell, which does not affect the outer shell.
export TESTO=`echo "111:222:333" |awk -F: '{print $2}'`
or all shell:
echo "111:222:333" | (
IFS="$IFS:"
read x TESTO y
IFS="${IFS%:}"
. . .
) # bash needs you to process inside a subshell, but ksh does not, uses the parent shell as the final shell on the pipe.
You can't pass awk variables to the shell directly. You could use an intermediate file or a (named) pipe, or you can use command substitution
TESTO=$(echo "111:222:333" | awk -F: '{print $2}')
or process substitution in bash/ksh93/zsh
read TESTO < <(echo "111:222:333" | awk -F: '{print $2}')
--
or a regular pipe in ksh and zsh only
echo "111:222:333" | awk -F: '{print $2}' | read TESTO
(also works with bash 4 with shopt -s lastpipe
in a non-interactive shell)