0

In shell script I am doing the following:

locationUrl=$(grep -r "Location:" output.txt)
fullUrl="http://test.com/temp/${locationUrl##*/}"
tempUrl="$fullUrl/tests"
echo $tempUrl

My expected output is

http://test.com/temp/226/tests

But I get this:

/tests/test.com/temp/226

The output.txt looks like bellow:

HTTP/1.1 100 Continue

HTTP/1.1 201 Created
Server: Apache-Coyote/1.1
Location: http://test.dev:8080/webservice/temp/226
Content-Type: application/xml

1 Answer 1

2

I suspect that output.txt has carrige returns in it. Piping the output through tr -d '\r' removes these. I suggest you try:

locationUrl=$(grep -r "Location:" output.txt | tr -d '\r')
entries="entries"
fullUrl="http://test.com/temp/${locationUrl##*/}"
tempUrl="$fullUrl/tests"
echo $tempUrl

Your original code is probably outputting http://test.com/temp/226^M/tests with the ^M causing your terminal to start rewriting the current line. You can check this by piping the output through less:

$ sh test.s | less
http://test.com/temp/226^M/tests
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.