Редактировать, для Bash 2.05 и выше :
#!/bin/bash
tab=$'\t'
while true # run forever, change to stop on some condition
do
threshold=100
until (( threshold < 40 ))
do
sleep 5
result=$(pmset -g ps)
threshold="${result#*iBox$tab}"
threshold="${threshold%\%*}"
done
shell_script
done
Оригинал, для Bash 3.2 и более поздних версий:
#!/bin/bash
pattern='[0-9]+' # works if there's only one sequence of digits in the output, a more selective pattern is possible if needed
while true # run forever, change to stop on some condition
do
threshold=100
until (( threshold < 40 ))
do
sleep 5
result=$(pmset -g ps)
[[ $result =~ $pattern ]]
threshold=${BASH_REMATCH[1]}
done
shell_script
done