Reputation: 261
I have such a script:
#!/bin/bash
temp=`inxi -xxx -w`
regex="(Conditions:(.+))(Wind:(.+))Humidity"
[[ $temp =~ $regex ]]
echo ${BASH_REMATCH[1]}
echo ${BASH_REMATCH[3]}
And it works cool, except such a detail - font color has changed, and now whole text became blue. How can I prevent it?
Upvotes: 2
Views: 444
Reputation: 1055
To avoid blue output:
#!/bin/bash
temp=$(inxi -xxx -w | sed -r 's/\x1B\[[0-9;]*[JKmsu]//g')
regex="(Conditions:(.+))(Wind:(.+))Humidity"
[[ $temp =~ $regex ]]
echo ${BASH_REMATCH[1]}
echo ${BASH_REMATCH[3]}
Changes I've made:
`
) is deprecated. Use $(command)
instead of `command`
.inxi
with the sed
regex onto I pipe it.To use blue output correctly:
#!/bin/bash
temp=$(inxi -xxx -w)
regex="(Conditions:(.+))(Wind:(.+))Humidity"
[[ $temp =~ $regex ]]
echo ${BASH_REMATCH[1]}
echo ${BASH_REMATCH[3]}
printf "\e[0m" # Reset the color.
\e
you can use \033
or \x1b
. All are the same thing.[0m
you can use [39;49;00m
.printf
you can use echo -e
, but I don't recommend it.Further reading: http://wiki.bash-hackers.org/scripting/terminalcodes
Upvotes: 1