user3382203 user3382203 - 4 months ago 7x
Linux Question

Remove white spaces from a variable

I want to remove the white spaces from a variable in Linux Shell and echo it on the terminal.
Following is my code:

echo "Enter your full name"
read fname
$fname | sed "s/ //g"

When I run the code it shows command not found.


You can't just call a variable (think of it as just a string value container). You need to echo it:

echo $fname | sed "s/ //g"