Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

concatenating strings in shell 1

Status
Not open for further replies.

DaveC426913

Programmer
Jul 28, 2003
274
CA
Clearly I don't know how to concatenate in shell script.


#!/usr/local/bin/bash
FOO1="foobie"
BAR1="bar"
echo "$FOO1/$BAR1"
#exit 0


I want it to output foobie/bar
What I'm getting is /barie
 
Code:
#!/bin/bash
FOO1="foobie"
BAR1="bar"
echo "$FOO1/$BAR1"
echo $FOO1/$BAR1
both work for me.
Code:
bash --version
GNU bash, version 3.00.16(1)-release (i386-pc-linux-gnu)
Copyright (C) 2004 Free Software Foundation, Inc.

seeking a job as java-programmer in Berlin:
 
REALLY??

You're typing sh test.sh at the prompt, and it spits out
foobie/bar?
 
And what about this ?
/bin/echo "$FOO1/$BAR1"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
That isn't going to slove the problem, this fails too:

BOB=$FOO$BAR
echo $BOB

This outputs the same thing (/barie), so it's nothing to do with the echo command itself.

I've been experimenting with simpler versions:

#!/usr/local/bin/bash
FOO="foobie"
BAR="bar"
BOB=$FOO$BAR
echo $BOB
#exit 0


This produces barbie (no funny comments!)

There is definitely something scwewy going on here...

 
Well, this is a fun one.
I can MAKE that symptom happen:

Code:
$ more doit
#!/bin/bash
FOO1="foobie^M"
BAR1="bar"
echo "$FOO1/$BAR1"

$ ./doit
/barie

Is there ANY possibility your $FOO1 variable has a control code embedded?



"Proof that there is intelligent life in Oregon. Well, Life anyway.
 
I downloaded your test script. Ran it, and got your results. Then, I removed the trailing ^M (Carriage Returns) from each line and got the desired results.

You should have a "dos2unix" type conversion script on your system. If not, use "vi" to remove those trailing ^M characters and try again.

"Proof that there is intelligent life in Oregon. Well, Life anyway.
 
Sigh. The editor I'm working in (Webmin File Manager Java Applet) has a little checkbox: DOS mode. It was checked. Unchecking it drops the extraneous carriage return from the end of each line.

You can see what my app was doing now. The variable $FOO actually was being populated with "foooo"+CR


Thanks all.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top