나는 이것이 당신이 원하는 무엇 확실하지, 당신을 위해 그것을 해결하기로 결정했습니다,하지만 난 가까이라고 생각 :
#!/bin/bash
a=0 #Initialize your variable to something
while [ $a -le 5 ]; do
read input < map_pipe;
if [ "$input" = "map finished" ]; then #Put double quotes around variables to allow values with spaces
a=$(($a + 1)) #Your syntax was off, use spaces and do something with the output
else
echo $input >> keys.txt #Don't re-read the pipe, it's empty by now and sort will wait for the next input
sort -u keys.txt > tmpfile #Instead sort your file, don't save directly into the same file it will break
mv tmpfile keys.txt
#sort -u keys.txt | sponge keys.txt #Will also work instead of the other sort and mv, but sponge is not installed on most machines
fi
done
일부 입력을 제공하여 스크립트를 확인 출력 – PesaThe
을 원하는 [ shellcheck] (http://shellcheck.net). – codeforester