1,105,578 Community Members

script appending string in beginning instead of in the end

Member Avatar
raul8
Light Poster
39 posts since Jul 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi,
I simply want to append a string at the end of another string.
But instead, it is replacing in the beginning.

#!/bin/bash
str1="/user/test"
echo $str1
echo ${str1}/program

I tried other techniques too but same result

Member Avatar
histrungalot
Posting Whiz in Training
280 posts since May 2008
Reputation Points: 32 [?]
Q&As Helped to Solve: 36 [?]
Skill Endorsements: 3 [?]
 
0
 

What did you want the output to look like?

Member Avatar
raul8
Light Poster
39 posts since Jul 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

What did you want the output to look like?

I just want to store "/user/test/program" in a separate variable.

But this "/program" can be anything.
Above I wrote the simplest version, for just explaining the issue.

Thanks

Member Avatar
L7Sqr
Veteran Poster
1,006 posts since Feb 2011
Reputation Points: 179 [?]
Q&As Helped to Solve: 168 [?]
Skill Endorsements: 11 [?]
 
0
 

When I run your example I get

/user/test
/user/test/program

I fail to see how that differs from what you want.

Member Avatar
cfajohnson
Junior Poster
199 posts since Dec 2008
Reputation Points: 10 [?]
Q&As Helped to Solve: 24 [?]
Skill Endorsements: 0 [?]
 
0
 
#!/bin/bash
str1="/user/test"
echo $str1
echo ${str1}/program

I just want to store "/user/test/program" in a separate variable.

But this "/program" can be anything.
Above I wrote the simplest version, for just explaining the issue.

If you want a separate variable, you need another assignment statement:

str1=/usr/test
str2=program
newvar=$str1/$str2
Member Avatar
raul8
Light Poster
39 posts since Jul 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

must be something wrong with my shell then

Member Avatar
L7Sqr
Veteran Poster
1,006 posts since Feb 2011
Reputation Points: 179 [?]
Q&As Helped to Solve: 168 [?]
Skill Endorsements: 11 [?]
 
0
 

You've yet to show what you expect to be output against what you are getting for output. There is definitely something wrong - it's just difficult to understand where currently.

Member Avatar
raul8
Light Poster
39 posts since Jul 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Mine was printing:
/user/test
/programst

But if I run on somewhere else like (ubuntu), then it working perfectly

Member Avatar
cfajohnson
Junior Poster
199 posts since Dec 2008
Reputation Points: 10 [?]
Q&As Helped to Solve: 24 [?]
Skill Endorsements: 0 [?]
 
0
 

Please post the exact script that you ran and that gave you a problem.

Post its output.

Post the output you want.

Member Avatar
Fest3er
Posting Whiz in Training
242 posts since Aug 2007
Reputation Points: 39 [?]
Q&As Helped to Solve: 35 [?]
Skill Endorsements: 0 [?]
 
0
 

I'll bet it is displaying exactly what's in the file; /programst is exactly what you should see if there's a <CR> after ...user/test. Use vi to edit the file. Then enter :set list; you'll probably see a <CR> (^M) in there somewhere. Or use od -c script_name; you should see \r in there.

It's a good idea to put text in quotes.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article