Just a sample of the Echomail archive
Cooperative anarchy at its finest, still active today. Darkrealms is the Zone 1 Hub.
|    TUXPOWER    |    Advocacy for the Linux operating system    |    1,237 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 67 of 1,237    |
|    Maurice Kinal to All    |
|    new and improved    |
|    01 Aug 11 19:13:24    |
   
   Hey All!   
      
   This should work for most versions of bash;   
      
    ----- split_address.function begins -----   
      
   split_address()   
   {   
    var=`echo "$1" | sed 's/[:/.]/ /g'`   
    set -- $var   
    ftn_addr=( $1 $2 $3 $4 )   
    unset var   
   }   
      
    ----- split_address.function ends -----   
      
   The above function returns the array $ftn_addr to both the commandline and   
   bash script(s) which is suitable for exporting to other functions, such as a   
   pkt header function with a origAddr array and a destAddr array where both are   
   split address arrays using the split_address() function.   
      
   Kudoes for the above go to the "Advanced Bash-Scripting Guide" version 6.3,   
   specifically "34-3. Piping the output of echo to a read" with a bit of   
   jiggery-pokery for this particular purpose.   
      
   Here is an example loop that puts the origAddr in the first four elements and   
   the destAddr in the last four elements suitable for exporting to the   
   pkt_header() function which will follow now that I have the split_address()   
   function working;   
      
    ----- Example {orig,dest}Addr array begins -----   
      
   for addr in "1:261/38.9" "1:261/38.0"   
   do   
    split_address "$addr"   
    pktAddr=( "${pktAddr[@]}" "${ftn_addr[@]}" )   
    unset ftn_addr   
   done   
      
   # echo entire array   
   $ echo ${pktAddr[@]}   
   1 261 38 9 1 261 38 0   
      
   # echo number of elements   
   $ echo ${#pktAddr[@]}   
   8   
      
    ----- Example {orig,dest}Addr array ends -----   
      
   What do you think so far? Personally I thought the hardcoded functions were   
   fine for my particular needs but the above makes this a tad more generic.    
   Also the addresses used above could be read in from a configuration file which   
   could differ for both orig and/or dest addresses. The above example would be   
   useful only for pktheader generation as well as for echomail only where the   
   destAddr part is the same. Netmail would probably use the identical addresses   
   as long as the netmail were targetting the sysop of the destAddr. I'd guess   
   that a seperate {orig,dest}Addr array for netmail(s) would be required and the   
   same idea using the split_address() function can be derived for that   
   particular need.   
      
   Comments and/or suggestions will be most welcome but I believe the above is   
   best all things considered.   
      
   Life is good,   
   Maurice   
      
   --- Msged/LNX 6.1.2   
    * Origin: The Pointy Stick Society (1:261/38.9)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca