Til Hund
Til Hund

Reputation: 1671

Bash - how to escape underscore in URL

I have a little script in bash on macOS, where I use an array with dates like 19000105 in the format yyyymmdd.

In that script I parse the dates of that array to a loop like:

for i in "${list[@]}"; do
    wget -A pdf -nc -E -nd --no-check-certificate URL$iURL$i_tif.pdf
done

where wget opens an URL to download pdf. In order to make it work I need to add the date twice to the URL at different parts.

The URL, however, contains at one point an underscore right after I insert the date, which needs to look like this: 19000105_tif/jpegs/.

I thought I need to add curled brackets like {$i}_tif/ to escape, however, the URL is parsed like %7B18500105%7D_tif/, which is wrong.

If I leave the curled brackets like $i_tif/, the URL is parsed like /jpegs/, where the date and tif-part before is not parsed at all and completely gone.

How can I add the dates correctly with an underscore in the URL right after?

Upvotes: 1

Views: 852

Answers (1)

Sonny
Sonny

Reputation: 3183

Using ${i} instead of $i should solve this

Upvotes: 3

Related Questions