We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,466 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

script appending string in beginning instead of in the end

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

5
Contributors
9
Replies
6 Days
Discussion Span
1 Year Ago
Last Updated
10
Views
raul8
Light Poster
39 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

What did you want the output to look like?

histrungalot
Posting Whiz in Training
280 posts since May 2008
Reputation Points: 76
Solved Threads: 36
Skill Endorsements: 1

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

raul8
Light Poster
39 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

When I run your example I get

/user/test
/user/test/program

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

L7Sqr
Practically a Posting Shark
851 posts since Feb 2011
Reputation Points: 253
Solved Threads: 155
Skill Endorsements: 7
#!/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
cfajohnson
Junior Poster
196 posts since Dec 2008
Reputation Points: 25
Solved Threads: 23
Skill Endorsements: 0

must be something wrong with my shell then

raul8
Light Poster
39 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.

L7Sqr
Practically a Posting Shark
851 posts since Feb 2011
Reputation Points: 253
Solved Threads: 155
Skill Endorsements: 7

Mine was printing:
/user/test
/programst

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

raul8
Light Poster
39 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

Post its output.

Post the output you want.

cfajohnson
Junior Poster
196 posts since Dec 2008
Reputation Points: 25
Solved Threads: 23
Skill Endorsements: 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.

Fest3er
Posting Whiz in Training
243 posts since Aug 2007
Reputation Points: 51
Solved Threads: 35
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.1058 seconds using 2.71MB