![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
Bash test for a dot terminatior in pop3 server LIST outputYes , an 0x2e dot.
I've been writing a script to talk to my pop email sever. Here is an actual short manual session of what i'm trying to script so far: Code:
I manually enter all the commands - USER , PASS etc. Ok , so you can see there that after the LIST command is issued I get a list of two-"word" strings each on a separate line terminated by a single dot on a line. In my script I use a while loop to 'read' each line that is output by LIST. The condition of the while loop is that damn dot. I can catch a dot I 'read' from my keyboard but when I try it on the output from the server it's not caught. I don't know if it's unicode or what but I'm stumped. Here is a demo of catching the dot with me doing the input: CPP / C++ / C Code:
When I run it the server list output stops , the dot is not detected so the loop continues and I end up hung on a read and must use ctrl-c to stop the process. CPP / C++ / C Code:
Obviously I am not too experienced with bash... HELP! , thanks, Howard(); |
|||
|
#2
|
|||
|
|||
Re: bash test for a dot terminatior in pop3 server LIST outputQuote:
What do you see if you change the loop output messages to be a little more informative: Code:
Looking at your logic, if the last message is simply a dot, I would expect to see something like Code:
Since your script never showed "Got dot", maybe there is some extra character on the line after the dot (A '\r' comes to mind; maybe some other whitespace.) By surrounding the response with ---><--- you can (maybe) see if there is some extra little "gift." So, for example, if the server is sending "\r\n" as line termination characters you might see something like Code:
If that's the case, then try something like the following for your loop: Code:
(This should work whether there is extra stuff after the dot or not.) Regards, Dave Last edited by davekw7x : 29-Sep-2009 at 02:55.
|
|
#3
|
|||
|
|||
Re: Bash test for a dot terminatior in pop3 server LIST outputCPP / C++ / C Code:
No offense to Mr. Bourne et al but all these bash nuances are mind boggling... You were right! There is a \r\n line ending. The read command strips the \n. I added a line to write each string to a file: CPP / C++ / C Code:
Code:
hmm, the fact that there is no 0x0a in each $REPLY string may be why I can't get it to test as expected. Code:
and using a for loop. That turned out to be a "beginning math evaluation" learning session. I think the for statement could be better but... it works for now. I have now added a test for your ${REPLY:0:1} and it tests true at the dot. So here is program as it stands now: Code:
Code:
indexing (I hate to say the word anymore) method later tonight... Thanks for the help Dave. back later. Howard(); |
|
#4
|
|||
|
|||
Re: Bash test for a dot terminatior in pop3 server LIST outputQuote:
You can't do that with Mr Bourne's original shell (traditionally named sh). That is one of the many useful features that was added to bash. (That's born-again sh---or is it bourne-again sh?) Note that for some Linux distributions (RedHat/Centos, for example), /bin/sh is a symbolic link to /bin/bash, so a shell script with #!/bin/sh as its first line is actually runs in a bash shell. With other distributions (Ubuntu, as I recall), /bin/sh is a shell that is very close to the original Bourne shell and doesn't have the Bash additions, so the first line of a script that uses bash-isms should be #!/bin/bash, not #!/bin/sh. Since many (most?) Linux distributions have bash as the default shell, you may not need anything in particular in the first line of a script unless you have changed the default to some other shell. (Some people like the Korn shell, ksh, for example, and ksh doesn't have this notation to address characters within a string.) A final note about variables in shell scripts: Old-timers who learned sh (maybe some not-so-old timers who learned from tutorials written by or copied from old-timers who learned sh) tend to use $xyz everywhere to get the value of a shell variable. This notation is still valid, but you can always use ${xyz} instead. The reverse is not true: There are a number of things that can be done with ${xyz} that do not compute if you try to use $xyz Some tutorials go into this in some detail, including examples where the newer notation works and the older wouldn't be possible (or in some cases could be used but would be more awkward.) Accessing substrings with the ${xyz:} notation is one example for which no such operation defined using the older notation. Regards, Dave |
Recent GIDBlog
Once again, no time for hobbies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Str_Misaligned in Double Link List | Peter_APIIT | C Programming Language | 1 | 29-Feb-2008 21:50 |
| [Include] Doubly-linked List | dsmith | C Programming Language | 6 | 14-Apr-2006 14:12 |
| fltk-2.0 cvs | Plumb | FLTK Forum | 20 | 13-Nov-2004 08:10 |
| Can't view pages from another machine on the Intranet | aevans | Apache Web Server Forum | 9 | 14-May-2004 03:26 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The