I have the following snippet in my .bashrc:

# Returns system load as percentage, i.e., '40' rather than '0.40)'.
function load()
    local SYSLOAD=$(cut -d " " -f1 /proc/loadavg | tr -d '.')
    # System load of the current host.
    echo $((10#$SYSLOAD))       # Convert to decimal.

When it's parsed, I get this error: bash: 100* : syntax error: operand expected (error token is " ") but I'm not sure why?

  • Are you running this on macOS? – nohillside Jan 17 at 19:17
  • With the system bash, or some other bash? This error is at shell startup or when you try to use the function? – Marc Wilson Jan 17 at 23:34
  • Does 100* occur somewhere else in this file? Don‘t see how this function can throw that error. – nohillside Jan 18 at 6:16

There is no /proc/loadavg on macOS, so SYSLOAD is most probably empty (or at least not numeric).

  • That'd be at run-time. The OP is not clear whether he is referring to trying to use the function, or to bash parsing the function at startup. cut(1) should blow up with an error if it was at runtime. It does here. – Marc Wilson Jan 17 at 23:34
  • @MarcWilson I didn’t even try. But same here: definition of function doesn’t throw any error, execution fails on the first line – nohillside Jan 18 at 6:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .