Я новичок в zenity, и я пытаюсь создать простой скрипт для загрузки файла с помощью zenity --file-selection и команды wc, чтобы получить количество слов этого файла. Я успешно создал форму, которая может использоваться для просмотра файла, но я не могу получить какой-либо результат. Не могли бы вы рассказать мне, где я делаю ошибку?
Мой текущий скрипт:
#creates a box
if zenity --entry \
--title="Word count" \
--text="Enter file location" \
--entry-text "File path"
then
#Zenity file selection code for browsing and selecting files
FILE=`zenity --file-selection --title="Select a File"`
case $? in
0)
echo "\"$FILE\" selected.";;
1)
echo "No file selected.";;
-1)
echo "An unexpected error has occurred.";;
esac
# To show the location in the text box
if zenity --entry \
--title="Word count" \
--text="Enter file location" \
--entry-text "$FILE"
then
#word counting code
word_count='wc $FILE'
zenity --info --title="Word Counted" --text="Counted words $word_count"
fi
fi
Я думаю, что правильный код может быть следующим:
#!/bin/bash
function count() {
word_count=$(wc -w < "$FILE")
zenity --info --title="Word Counted" --text="Counted words $word_count"
}
function choose() {
FILE="$(zenity --file-selection --title='Select a File')"
case $? in
0)
count;;
1)
zenity --question \
--title="Word counter" \
--text="No file selected. Do you want to select one?" \
&& choose || exit;;
-1)
echo "An unexpected error has occurred."; exit;;
esac
}
choose