idioms for returning multiple values in shell scripting

In the special case where your values never contain spaces, this read trick can be a simple solution:

get_vars () {
  #...
  echo "value1" "value2"
}

read var1 var2 < <(get_vars)
echo "var1='$var1', var2='$var2'"

But of course, it breaks as soon as there is a space in one of the values. You could modify IFS and use a special separator in your function’s echo, but then the result is not really simpler than the other suggested solutions.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)