Why does this cause an infinite loop?
#!/bin/bash
while [[ "$(ipcs | awk '{print $2}')" != "Semaphore" ]]; do
#Gonna get rid of the echo after working
echo "$(ipcs | awk '{print $2}')"
#I wanna keep this
ipcrm shm "$(ipcs | awk '{print $2}')"
#I want this run after breaking out of the loop until I reach the string
#Message.
ipcrm -s "$(ipcs | awk '{print $2}')"
done
echo
exit 0
I have verified I eventually get Semaphore so it should break out of the while loop.
$ echo $(ipcs | awk '{print $2}')
Shared shmid 262145 294914 2326531 Semaphore semid Message msqid
$ ipcs
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x00000000 262145 bob 600 393216 2 dest
0x00000000 294914 bob 600 393216 2 dest
0x00000000 2490371 bob 600 998400 2 dest
------ Semaphore Arrays --------
key semid owner perms nsems
------ Message Queues --------
key msqid owner perms used-bytes messages
$ echo $(ipcs | awk '{print $1}')
------ key 0x00000000 0x00000000 0x00000000 ------ key ------ key
$ echo $(ipcs | awk '{print $2}')
Shared shmid 262145 294914 2490371 Semaphore semid Message msqid
"Semaphore"
, you could use*Semaphore*
without the quotes (""
). – geedoubleya Oct 9 '14 at 13:55ipcs -s
to check only for Semaphore. – Archemar Oct 9 '14 at 13:56while [[ 1 ]]
. – slm♦ Oct 9 '14 at 14:19