0

I have a shell script that I want to run many times. Each time, I want to use a different argument that comes from a CSV file. The file is very simple:

code1-code2-01
code1-code2-02
code1-code2-03
code1-code2-04

and so on.

My script looks like:

#!/bin/bash
env="prod"
IDS_FILE="some_file.csv"

arr_ids=() 
while read line || [ -n "$line" ]
do
    arr_ids+=("$line")
done < $IDS_FILE

echo "sudo ./some_script.sh -i ${arr_ids[0]} -e $env"

I'm using echo to debug the problem because when I run the script, I gets problems whenever I call the variable that ${arr_ids[0]}. When I echo, though, I get the following:

 -e prodome_script.sh -i code1-code2-01

I'm guessing it's some kind of syntax issue that I'm not aware of.

2
  • 1
    Your input file has Windows-style CRLF line endings. Convert them to Unix LF line endings using do2sunix as shown in the duplicates Commented Jan 30 at 4:50
  • See also Understanding "IFS= read -r line" and you probably need somescript -i line1 -i line2 -e env rather than somescript -i line1 line2 -e env if somescript parses its options the standard way. Commented Jan 30 at 12:01

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.