他是朋友。我正在創建一個腳本文件,以便能夠讀取用戶輸入並根據我詢問的問題顯示輸出。當我單獨運行選擇時,它們工作正常,但無法弄清楚爲什麼他們不會顯示,當我把碎片放在一起。在Linux中從用戶選擇bash shell獲取輸出時出錯
#!/bin/bash
while test $loop = "y"
do
echo "$CLEAR"
clear
tput cup 5 12 ; echo "L- List all wines by name in alphabetical order."
tput cup 6 12 ; echo "C- Count all wines in each type and list all 5 types with their count."
tput cup 10 12; echo "E- Exit the program."
read choice || continue
case $choice in
[Ll]) file="/home/students/domie/wine.txt"; sort -t ":" -k2 $file;; #no output here
[Cc]) ./count ;; #look below for count script
[Ee]) clear; exit ;; #this works when script runs
*) tput cup 14 4; echo "Invalid Code,Press Enter and Try Again"; read choice ;;
esac
done
和計數腳本:
$六計數
while IFS=":" read -ra line; do
if ((${line[2]} == 2)); then
IFS=":" && echo "${line[*]}"
((count++))
fi
done < /home/students/domie/wine.txt
echo "Count = $count"
編輯: wine.txt
你是什麼_putting平均碎片R_? – devnull
從'wine.txt'文件中發佈示例數據。 –
當我運行主腳本,並選擇選項L(按名稱按字母順序列出所有葡萄酒)列表不會顯示出來。當我單獨運行這個命令時,它將按順序顯示這個列表,但是當我把它放在主腳本中時它不會。 file =「/ home/students/domie/wine.txt」; sort -t「:」-k2 $文件 – endri