In bash scripts I try to keep my variables local to functions wherever I can and then pass what I need out of functions like bellow
#!/bin/bash
function FUNCTION() {
local LOCAL="value"
echo "$LOCAL" # return this variable
}
GLOBAL=$(FUNCTION)
echo "$GLOBAL"
But is it possible to do this while including the function's own echos so that if the function has it's own messages to output I don't have to catch them in a variable
#!/bin/bash
function FUNCTION() {
local LOCAL="value"
echo "$LOCAL" # return this variable
echo "This function is done now" # do not return this variable
}
GLOBAL=$(FUNCTION)
echo "$GLOBAL" # should only echo 'value'
function foo()
syntax? You can get better POSIX compatibility with 9 less keypunches. – Arthur2e5 Oct 15 '15 at 12:44