Timeline for Bash not equal string comparison
Current License: CC BY-SA 3.0
10 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Oct 11, 2014 at 2:53 | comment | added | terdon♦ | @cokedude since this seems to have answered your question (given that you're using this code in your new question) you might want to consider accepting it which will signify to everyone that your issue's been resolved. | |
| Oct 9, 2014 at 16:36 | comment | added | G-Man Says 'Reinstate Monica' |
Bash while loops do have the ability to read one line at a time, but not the way you coded it. $(some_command) runs that command (to completion) and squashes its output to a single line. See slm's answer for how to do what you want.
|
|
| Oct 9, 2014 at 14:26 | comment | added | cokedude | @JohnWHSmith so bash while loops don't have the ability to read one line at a time? I would think $2 would be equal to Shared, then shmid, then 262145, then 294914, then 2326531, then Semaphore, then semid, then Message msqid. Thats not exactly what I was trying to do. I edited my comment above. I want a command to be executed until I reach the string "Semaphore". Then I want another command to be executed until I reach the string "Message" | |
| Oct 9, 2014 at 14:22 | history | edited | John WH Smith | CC BY-SA 3.0 |
deleted 44 characters in body
|
| Oct 9, 2014 at 14:16 | history | edited | John WH Smith | CC BY-SA 3.0 |
added 427 characters in body
|
| Oct 9, 2014 at 14:10 | comment | added | Isaac |
To put it simpler, ipcs output contains Semaphore, but it is not Semaphore only.
|
|
| Oct 9, 2014 at 14:05 | comment | added | John WH Smith |
Your $(...) result is never equal to semaphore. It is always equal to the full line (Shared ...). Since your != is never met, the loop never ends. You don't want to test the whole result every time, you want to iterate over it: this is what the for-loop is designed to do. Here, I iterate over the result, and break the loop when I meet Semaphore, which is what you seemed to be trying to do with your while loop.
|
|
| Oct 9, 2014 at 14:04 | comment | added | cokedude | how are Semaphore and Semaphore not equal? I would think when they are equal it would exit. | |
| Oct 9, 2014 at 13:59 | history | edited | John WH Smith | CC BY-SA 3.0 |
added 127 characters in body
|
| Oct 9, 2014 at 13:53 | history | answered | John WH Smith | CC BY-SA 3.0 |