我試圖將ID添加到文件。該文件是這樣的:雖然循環不遍歷文件
field1:field2:field3:field4
我要檢查,如果第二場已經存在(輸出消息給用戶),或者如果它不能(將其添加到文件一次我從更多信息用戶)。我已經寫了一個循環來完成這個任務,但是每當我運行腳本的這一部分時,它只會滯後,從不執行。我認爲問題在於我的while循環沒有正確捕獲每一行。
40 checkID()
41 {
42
43 local input
44 local line
45 while : ; do
46 read -p "Enter id (or ENTER to quit):" input
47 [ -z "$input" ] && return 1
48 while read line; do
49 if ! grep -q "$(cut -d: -f2)" "$file"; then
50 echo "$input"
51 else
52 error "id '$input' already exists in the file"
53 fi
54 done
55 done
56 }
** 48 **行表示它需要**輸入stdin。你嘗試輸入什麼? @Whoppa – akawhy