echo from a function that returns a string to the calling function causes newlines to appear before the string

Home / Uncategorized / echo from a function that returns a string to the calling function causes newlines to appear before the string

Question:
I am trying to return an S3 link from a bash function using echo.
function1(){
sample_code_line1
sample_code_line2
S3_LINK="http://xxxx-xxxxxx.s3.amazonaws.com/KRD-4386801114873926480_15224268_komaccas-monopoly-app-au-ios-production-bnfvp.Event201704301400-201705071400-TZ_Australia-NSW.csv?AWSAccessKeyId=AKIAJ4JWD2OCXDYVOG4A&Expires=1503638429&Signature=oEsbOnqkEDMuyCsN%2Bwu%2FJS7%2F27U%3D"
echo "$S3_LINK"
}

S3_REPORT_LINK="$(function1 "${arg1}" "${arg2}")"
curl -o report.csv "${S3_REPORT_LINK}"

The curl command produces an error because the returned string containing the S3 link has preceding newlines to it. Although, I have no issues removing the newlines; I am curious to know why this behavior occurs in the first place. When I run the script in debug mode, I can clearly see that the variable S3_LINK carries the string without any newlines but when passed does.


Answer:

Read more

Leave a Reply

Your email address will not be published. Required fields are marked *