Sample Header Ad - 728x90

Bash Scripting echo locally in a function

24 votes
3 answers
56375 views
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'
Asked by TheLovelySausage (4443 rep)
Oct 15, 2015, 11:07 AM
Last activity: Oct 17, 2024, 08:38 AM