Just a little thing I'd like to add. The command above worked perfectly for me, but it couldn't see my name of the partition and wouldn't mount with Disk Utility, so I had to mount the drive in Terminal first: (my disk is disk0s3)
diskutil mount /dev/disk0s3
(in case someone else runs into the same thing I did, just always remember to check which partition is yours)
and TADA, my partition popped up with correct name and all.
I am still on Snow Leopard, btw, and everyting is in order now. You've made my day! You helped me so, so much! Thank you!
Вы должны заменить "failed"
на "\"failed\""
. Должно быть:
while read status name date; do
case "$status" in
'aborted')
echo -1
;;
"\"failed\"")
echo -1
;;
'succeeded')
echo 0
;;
*) echo 0
esac
exit 0
done<st.txt
Также рассмотрите возможность использованияread with -r
.
Есть и более простой способ сделать то, что вы хотите:
if [ "$(cut -d ' ' -f1 st.txt)" = "\"failed\"" ]
then
printf -- "-1\n"
fi
Другим решением является добавление одинарных кавычек вокруг -строк в двойных кавычках:
while read status name date; do
case "$status" in
'"aborted"')
echo -1
;;
'"failed"')
echo -1
;;
'"succeeded"')
echo 0
;;
*)
echo 0
esac
exit 0
done < st.txt