Try this:
echo "$HEAD" | tr -s " "
or maybe you want to save it in a variable:
NEWHEAD=$(echo "$HEAD" | tr -s " ")
Update
To remove leading and trailing whitespaces, do this:
NEWHEAD=$(echo "$HEAD" | tr -s " ")
NEWHEAD=${NEWHEAD%% }
NEWHEAD=${NEWHEAD## }
More Related Contents:
- Why does shell ignore quoting characters in arguments passed to it through variables? [duplicate]
- How can I use a file in a command and redirect output to the same file without truncating it?
- How to check if a variable is set in Bash
- Why does a space in a variable assignment give an error in Bash? [duplicate]
- Shell equality operators (=, ==, -eq)
- What is a simple explanation for how pipes work in Bash?
- Indirect variable assignment in bash
- redirect COPY of stdout to log file from within bash script itself
- Shell script to delete directories older than n days
- How to recursively find the latest modified file in a directory?
- How to extract directory path from file path?
- Shell: How to call one shell script from another shell script?
- Quick-and-dirty way to ensure only one instance of a shell script is running at a time
- Process all arguments except the first one (in a bash script)
- How to represent multiple conditions in a shell if statement?
- Generating permutations using bash
- What does the Bash operator
- Value too great for base (error token is “09”)
- How to escape history expansion exclamation mark ! inside a double quoted string?
- firebase-tools “-bash: firebase: command not found”
- Capture both stdout and stderr in Bash [duplicate]
- Using a variable in brace expansion range fed to a for loop
- Source files in a bash script
- executing shell command in background from script [duplicate]
- Determine if a function exists in bash
- while loop to read file ends prematurely
- Difference between wait and sleep
- How to get the first line of a file in a bash script?
- Save file to specific folder with curl command
- Is there a way to get my emacs to recognize my bash aliases and custom functions when I run a shell command?