0
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?
Have you considered using something like puppet instead? The link has an example of your exact use case.
– hhoke1 – 2018-04-20T15:27:13.737No, puppet seems to be an overkill for this simple case. – coverflower – 2018-04-20T15:38:00.883
What is
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. – Kamil Maciorowski – 2018-04-20T17:08:46.993@Kamil Maciorowski: Fill the 3 arrays – coverflower – 2018-04-20T17:12:34.687
I have found this here: https://stackoverflow.com/questions/30146241/error-with-linux-whiptail-dialog-arguments-from-bash-variable which works. The middle argument is within single quotes and left and right arguments are not. This must be the problem but I don't know how to fix it...
– coverflower – 2018-04-20T17:21:02.673