I have this CSV with 2 column: one contains names and the other file names with no extension.
When I parse it and store the values in 2 array I'd like to add a path and PDF extension to the file names but when I do it, I get something like this:
Giacomos-MBP:test Jack$ ./test.sh -p e.csv -a 2017
.pdf://www.test.com/2017/03cr14a076d
.pdf://www.test.com/2017/03bg15a365d
.pdf://www.test.com/2017/03bs15a451d
.pdf://www.test.com/2017/03bg15a440d
.pdf://www.test.com/2017/03cr16a570d
.pdf://www.test.com/2017/03bg15a794d
I expect
http://www.test.com/2017/03bg15a794d.pdf
instead
Anybody knows why? It looks like the extension goes in front of the path
This is my script
#!/bin/bash
while getopts p:a: arg
do
case $arg in
p) multi=$OPTARG
;;
a) anno=$OPTARG
;;
esac
done
declare -a citta
declare -a codice
i=0
while IFS=";" read col1 col2 do
citta[$i]=$col1;
codice[$i]=$col2;
((i++))
done < $multi
cartella='http://www.test.com/'$anno'/'
total=${#citta[*]}
for (( i=0; i<=$(( $total -1 )); i++ )) do
last="${codice[$i]}.pdf"
echo $cartella$last
done
As @FredrikPihl has suggested this is the output I get
Giacomos-MBP:test Jack$ ./test.sh -p e.csv -a 2017
+ getopts p:a: arg
+ case $arg in
+ multi=e.csv
+ getopts p:a: arg
+ case $arg in
+ anno=2017
+ getopts p:a: arg
+ declare -a citta
+ declare -a codice
+ i=0
+ IFS=';'
+ read col1 col2
+ citta[$i]=Agnadello
+ codice[$i]=$'03cr14a076d\r'
+ (( i++ ))
+ IFS=';'
+ read col1 col2
+ citta[$i]=Arcene
+ codice[$i]=$'03bg15a365d\r'
+ (( i++ ))
+ IFS=';'
+ read col1 col2
+ citta[$i]=Artogne
+ codice[$i]=$'03bs15a451d\r'
+ (( i++ ))
+ IFS=';'
+ read col1 col2
+ citta[$i]=$'\r'
+ codice[$i]=
+ (( i++ ))
+ IFS=';'
+ read col1 col2
+ total=4
+ cartella=http://www.test.com/2017/
+ (( i=0 ))
+ (( i<=3 ))
+ last=$'03cr14a076d\r.pdf'
+ echo $'http://www.test.com/2017/03cr14a076d\r.pdf'
.pdf://www.test.com/2017/03cr14a076d
+ (( i++ ))
+ (( i<=3 ))
+ last=$'03bg15a365d\r.pdf'
+ echo $'http://www.test.com/2017/03bg15a365d\r.pdf'
.pdf://www.test.com/2017/03bg15a365d
+ (( i++ ))
+ (( i<=3 ))
+ last=$'03bs15a451d\r.pdf'
+ echo $'http://www.test.com/2017/03bs15a451d\r.pdf'
.pdf://www.test.com/2017/03bs15a451d
+ (( i++ ))
+ (( i<=3 ))
Giacomos-MBP:test Jack$