using global var as return value instead of an echo and changed seperator from \n to a single space
changed check function to accept name of return value of command to be checked