I have a small bash script as below
function getUptime() {
uptime 2>/dev/null
return "$?"
}
resultReceived=$(getUptime)
echo "Result: $resultReceived"
And when I execute the script, instead of 0
I am getting uptime
command output. Where I am doing the mistake. Please help.
Debug Output
tmp bash -x testingscript.sh
++ getUptime
++ uptime
++ return 0
+ resultReceived='11:47 up 3 days, 19:24, 7 users, load averages: 1.88 1.78 2.04'
+ echo 'Result: 11:47 up 3 days, 19:24, 7 users, load averages: 1.88 1.78 2.04'
Result: 11:47 up 3 days, 19:24, 7 users, load averages: 1.88 1.78 2.04