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

What did you want the output to look like?

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

When I run your example I get

/user/test
/user/test/program

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

#!/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

must be something wrong with my shell then

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.

Mine was printing:
/user/test
/programst

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

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

Post its output.

Post the output you want.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.