Para salvar as saídas de find em uma matriz bash use isto:
unset options i
while IFS= read -r -d $'select opt in "${options[@]}" "Stop the script"; do
case $opt in
*.war)
echo "War file $opt selected"
# processing
;;
"Stop the script")
echo "You chose to stop"
break
;;
*)
echo "This is not a number"
;;
esac
done
' f; do
options[i++]="$f"
done < <(find /dir/ -maxdepth 1 -type f -name "*.war" -print0 )
-
readlê a entrada defindnull delimitada (-d $').$options'- O array
findé preenchido com os nomes dos arquivos.
- O array
-
-type fprocura apenas por arquivos (-maxdepth 1) no diretório fornecido (.war) com final-name "*.war"(-print0) e os imprime delimitados pelo caractere nulo ( %code% ).
O menu de seleção pode ser feito assim:
1) /dir/old.war
2) /dir/debug.war
3) /dir/release.war
4) Stop the script
#? test
This is not a number
#? 2
War file /dir/debug.war selected
#? 4
You chose to stop
Funciona da seguinte forma:
unset options i
while IFS= read -r -d $'select opt in "${options[@]}" "Stop the script"; do
case $opt in
*.war)
echo "War file $opt selected"
# processing
;;
"Stop the script")
echo "You chose to stop"
break
;;
*)
echo "This is not a number"
;;
esac
done
' f; do
options[i++]="$f"
done < <(find /dir/ -maxdepth 1 -type f -name "*.war" -print0 )