I am trying to get the return Boolean value of the command: sysctl debug.lowpri_throttle_enabled
, in a shell script (run with zsh).
This command is for knowing whether macOS enables the limit of speed of low-order tasks (i.e. time machine).
Here is the script I have done now:
value=$(sysctl debug.lowpri_throttle_enabled)
echo $value
The output I got is:
>>>debug.lowpri_throttle_enabled: 0
But I just want 0
/1
as output, how can I just get the boolean value but not the whole string? Thanks.
CodePudding user response:
I have found the solution. Reference : https://ss64.com/osx/sysctl.html
With adding -n
as option, it will only return the value.
e.g.
>>>sysctl -n debug.lowpri_throttle_enabled
0
>>>sudo sysctl debug.lowpri_throttle_enabled=1
>>>sysctl -n debug.lowpri_throttle_enabled
1
According to the description, -n
is for:
Show only variable values, not their names. This option is useful for setting shell variables.
And -b
is for:
Force the value of the variable(s) to be output in raw, binary format. No names are printed and no terminating newlines are output.
But I don't know why only -n
works in this case, -b
doesn't.