user3382203 user3382203 - 2 years ago 152
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.

Answer Source

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"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download