On Ubuntu 16.04, I have a bash script which I run as root. I want to remove all spaces from the user's input, and assign the trimmed string to a variable.
read -p "Enter username: " USERNAME
echo "$USERNAME" | sed s/' '/''/g
TRIM="$USERNAME" | sed s/' '/''/g
echo $TRIM
echo "Done"
Here's some sample input and output:
Enter username: h j k l
hjklDone
$TRIM is empty.
What change do I need to make to get $TRIM to contain the result?