Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have done the following at command line:

text="name with space"

echo $text

name with space

I am trying to use tr -d ' ' to remove the spaces and have a result of:

namewithspace

I've tried a few things like:

text=echo $text | tr -d ' '

No luck so far so hopefully you wonderful folk can help!

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Just modify your text variable as below.

text=$(echo $text | tr -d ' ')
share|improve this answer
    
Wonderful! I was soooo close. As a noob I am pleased I was heading the right direction! Thank you for the fast response as well, as soon as I have waited 8 minutes I will submit this as the answer! –  user3347022 3 hours ago
    
@user3347022, you are welcome :) –  Ramesh 2 hours ago

In Bash, you can use Bash's built in string manipulation. In this case, you can do:

> text="some text with spaces"
> echo "${text// /}"
sometextwithspaces

For more on the string manipulation operators, see http://tldp.org/LDP/abs/html/string-manipulation.html

However, your original strategy would also, work, your syntax is just a bit off:

> text2=$(echo $text | tr -d ' ')
> echo $text2
sometextwithspaces
share|improve this answer
    
I didn't even think of that, was in a tr mood working on this! Great answer as well! –  user3347022 1 hour ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.