Prasad
Prasad

Reputation: 53

Concatenating a string to an existing URL String - shell script

I have a string "http://localhost:8080/queue/item/259/" stored in the variable: queuedItemURL. I need to append string "api/json?pretty=true".

My script:

echo "================="
echo $queuedItemURL
queuedItemURL+="api/json?pretty=true"
echo $queuedItemURL
echo "============================="

The output I get is:

================= 
http://localhost:8080/queue/item/259/ 
api/json?pretty=true0/queue/item/259/
=============================

It seems there is some string replacement happening due to '/'. Please help me in getting the string concatenated properly.

Upvotes: 1

Views: 2602

Answers (1)

OznOg
OznOg

Reputation: 4722

I think the problem is your $queuedItemURL variable which has a hidden \r;

try:

queuedItemURL=$(echo $queuedItemURL | tr -d '\r')

before using it

Upvotes: 4

Related Questions