I have a bash script where I get the disk usage, for example
60%. How can I remove the
% symbol? Using grep or awk?
There is no need for external tools like
sed as bash can do it on its own since forever.
This statement removes the shortest matching substring (in this case an escaped
%) from the end of the variable. There are other string manipulating facilities built into bash. It even supports regular expressions. Generally, most of the stuff you normally see people using
grep for can be done using a bash builtin. It's just almost noody knows about that and brings the big guns...
See http://tldp.org/LDP/abs/html/parameter-substitution.html#PSOREX1 for more information.