I will preface this by saying I know next to nothing about bash, so I hope to get some clarification.
I have a function in which I can pass a here string or heredoc like so, and it will return a data file. The following examples work perfectly.
# Example 1
fetch_urls <<< "https://n5eil01u.ecs.nsidc.org/DP4/SMAP/SPL3SMP.008/2019.03.09/SMAP_L3_SM_P_20190309_R18290_001.h5"
# Example 2
urls = "https://n5eil01u.ecs.nsidc.org/DP4/SMAP/SPL3SMP.008/2019.03.09/SMAP_L3_SM_P_20190309_R18290_001.h5
https://n5eil01u.ecs.nsidc.org/DP4/SMAP/SPL3SMP.008/2019.03.08/SMAP_L3_SM_P_20190308_R18290_001.h5"
fetch_urls <<< "$urls"
So I can pass my function a string of urls either manually or through a variable. However, when I attempt to read a string of urls from a text file and store it into my url variable to pass to my function, everything breaks down.
I've tried my best to troubleshoot this, but I am not sure what is happening here. When I do echo "$urls" everything looks right.
urls = "https://n5eil01u.ecs.nsidc.org/DP4/SMAP/SPL3SMP.008/2019.03.09/SMAP_L3_SM_P_20190309_R18290_001.h5
https://n5eil01u.ecs.nsidc.org/DP4/SMAP/SPL3SMP.008/2019.03.08/SMAP_L3_SM_P_20190308_R18290_001.h5"
# Will not work
fetch_urls <<< echo "$urls"
# Will work
fetch_urls <<< "$urls"
What is going on here? I thought maybe echo might remove the newline character, and so that is why my function would breakdown. So I tried adding a newline character at the end using `printf '%s\n', but this still does not work.
# This is how I am extracting my urls from my text file
urls="$(while read -r line; do echo "$line"; done < urls.txt)"
# Feeding this into
fetch_urls <<< "$urls"
# or
fetch_urls <<< echo "$urls"
# does not work.
# But setting urls to a string does?
# echo "$urls" looks just like the string!
<<<must be a string, not a command. If you want to pass the output of a command as input, use a pipe:echo "$urls" | fetch_urls. Or I suppose you could capture the output of the command with$( )and pass that with a here-string:fetch_urls <<< "$(echo "$urls")"urls=$(cat yourflle)would be enough. Also your initial question was three hours before this one and you still state that you know nothing about bash. 3 hours is a hell of a lota time to learn a new skill. You could start for example here: guide.bash.academy