0

I have the following script I made using CURL for a task, I want to download several JSON files from different repos, a JSON per language in its corresponding ISO Lang Code. The problem I have is that after running the code, the first Language "bg" in the Array is not downloaded in the corresponding local folder, the rest are downloaded normally. Can anyone point me to what I need to fix? The code is below:

```#!/bin/bash

repo=("repo1" "repo2" "repo3")

lang=("bg" "cs" "da" "de" "el" "en" "en_gb" "en_us" "es" "fi" "fr" "hu" "it" "ja" "nl" "no" "pl" "pt" "ro" "ru" "sk" "sv" "th" "tr" "zh")

for repo in "${repo[@]}"
    do
        for lang in "${lang[@]}"
            do
            curl --user "${USER}":"${APP_PASSWORD}" -O "https://api.bitbucket.org/2.0/repositories/<company>/${repo}/<url>/translations/${lang}.json" --output-dir "C:/Mylocalfiles/Curl/${repo}/"
        done
    done ```

Thanks everyone for your help!

After all your suggestions, I fixed the code, and here's the updated one. it works perfectly!

#!/bin/bash

repo=("repo1" "repo2" "repo3")

lang=("bg" "cs" "da" "de" "el" "en" "en_gb" "en_us" "es" "fi" "fr" "hu" "it" "ja" "nl" "no" "pl" "pt" "ro" "ru" "sk" "sv" "th" "tr" "zh")

for repo_id in "${repo[@]}"
    do
        for lang_code in "${lang[@]}"
            do
            curl --user "${USER}":"${APP_PASSWORD}" -O "https://api.bitbucket.org/2.0/repositories/<company>/${repo_id}/<url>/translations/${lang_code}.json" --output-dir "C:/Mylocalfiles/Curl/${repo_id}/"
        done
    done ```




  • 1
    Welcome to Stack Overflow. What is ```VAR```? – ewong Apr 28 '22 at 00:29
  • 3
    Don't use the same variable (you do this for `REPO` and `LANG`) as the name of an array and a scalar. I'm surprised the shell lets you do that (does it?). You never use `GAME` after populating it, is that deliberate or a bug? – Ed Morton Apr 28 '22 at 00:30
  • 2
    As the [bash tag](https://stackoverflow.com/tags/bash/info) you used in your question instructs you to do - copy/paste your shell script(s) into https://shellcheck.net and fix the problems that tool tells you about before posting here if you still have a problem afterwards. – Ed Morton Apr 28 '22 at 00:36
  • 1
    It's dangerous to use `ALL_UPPERCASE` variable names. They may clash with environment variables or special shell variables. See [Correct Bash and shell script variable capitalization](https://stackoverflow.com/q/673055/4154375). The `LANG` variable in the code clashes with a standard environment variable. See [environ(7)](https://man7.org/linux/man-pages/man7/environ.7.html). – pjh Apr 28 '22 at 01:08
  • 1
    Aside from the problem naming your variable `LANG`, I suggest that you run your code with `set -x` turned on, so that you see what curl requests are actually processed. – user1934428 Apr 28 '22 at 07:45
  • You are defining `REPO` as an array, but use it as if it were a scalar. Is this intentional? bash does not forbid it, but it may point to a bug in the logic in your program. – user1934428 Apr 28 '22 at 07:50
  • Hey all, thanks for your prompt replies! I am new to this so literally just understanding the tool and how to interct here. After pointing out the flaws, I made the fixes and corrected to be everything lower case. – userjaguero1521 Apr 28 '22 at 13:21
  • @JosueAgüero You're still using the same name (`lang`) for the array of all languages, and also for a specific language from that list; use different names to avoid conflict. – Gordon Davisson Apr 28 '22 at 17:28

0 Answers0