by @saigowthamr

How to trim whitespace of a string in Bash

Home » bash » How to trim whitespace of a string in Bash

We can remove the leading and trailing whitespaces of a string by using the xargs in Bash.

Here is an example:

str="   how are you  "
echo $str | xargs

Output: trimmed string

how are you

Best Web Development courses