I'm trying to to write a bash script to automate the installation of my packages. So the idea is to read a .csv file (packages.csv) like this one:
pkg,Description,option
wget,file downloader,on
curl,tool to transfer data from or to a server,on
nano,text editor for Unix-like computing systems,off
emacs,An extensible customizable free/libre text editor — and more,on
build an array for each column (without header) and then pass the arrays to a dialog checklist.
#!/bin/bash
input="packages.csv"
while IFS=',' read -r col1 col2 col3
do
for a in $col1; do
array_col1+=("$a")
done
for b in $col2; do
array_col2+=("$b")
done
for c in $col3; do
array_col3+=("$c")
done
done < "$input"
array1=("${array_col1[@]:1}")
array2=("${array_col2[@]:1}")
array3=("${array_col3[@]:1}")
let num=${#array2[*]}-1
for i in $(seq 0 $num); do
list[i]=$(echo ${array1[i]} ${array2[i]} ${array3[i]})
done
OPTION=$(dialog --checklist "Choose packages:" \
10 60 4 \
${list[*]})
exitstatus=$?
if [ $exitstatus = 0 ]; then
echo "$OPTION"
else
echo "Cancel"
fi
I did get it working at some point but without any spaces in the description. After I did some changes in order to include the spaces it doesn't work at all. How can I fix it? Actually in my .csv file I have more than 3 columns but bash checklist expects 3 arguments. Is it possible to somehow include them in the checklist?
for a in $col1; do
for? And the same forb
andc
? I think when you do it forb
,$col2
undergoes word splitting with standardIFS
; then you get multipleb
-s while still parsing a single line.