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

Edited by raul8: n/a

5
Contributors
9
Replies
10
Views
5 Years
Discussion Span
Last Post by Fest3er
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

Edited by raul8: n/a

0

When I run your example I get

/user/test
/user/test/program

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

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
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.

0

Mine was printing:
/user/test
/programst

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

0

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

Post its output.

Post the output you want.

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.