What about something like following:

while read line; do
    case "x$line" in
       x)
           # empty line, do nothing
       ;; 

       x[ | x])
           # you don't like brackets, do nothing too
       ;;

       *)
           # Everything else
           set -- $line
           # Now $1 == user, $3 == passwd (if any)
           # do whatever you like with them
       ;;
    esac
done < passwd.fake


Valery
--- Maxim Vexler <[EMAIL PROTECTED]> wrote:

> Hi list, any bash gurus in the house ?
> 
> I'm having the most annoying issue with bash, one
> related to space
> delimited variables.
> I'd like to get a list in the form of :
> <<<
> user1 password1
> user2 password2
> >>>
> 
> Instead I'm getting:
> <<<
> user1
> password1
> user2
> password2
> >>>
> 
> Here's an example:
> 
> san-svn:/var/lib/svn# cat passwd.fake
> [users]
> user1 = password1
> user2 = password2
> 
> 
> san-svn:/var/lib/svn#
> 
> I'd like to automate this the import from this file
> into something like
> san-svn:# htpasswd -b passwd.real user1 password1
> 
> For this I've tried this voodoo:
> 
> san-svn:/var/lib/svn# for pair in `awk
> '/^[^[].+[^\n]$/ {print $1,
> $3}' passwd.fake`; do htpasswd -b passwd.true
> "$pair"; done
> 
> This does not work for the following reason:
> 
> san-svn:/var/lib/svn# for pair in `awk
> '/^[^[].+[^\n]$/ {print $1,
> $3}' passwd.fake`; do echo "$pair"; done
> user1
> password1
> user2
> password2
> 
> 
> I've tried the following workarounds, that didn't
> worked:
> 
> san-svn:/var/lib/svn# IFS='\n' for pair in `awk
> '/^[^[].+[^\n]$/
> {print $1, $3}' passwd`; do echo $pair; done
> -bash: syntax error near unexpected token `do'
> 
> san-svn:/var/lib/svn# IFS='!\n' for pair in `awk
> '/^[^[].+[^\n]$/
> {print $1, $3}' passwd`;! do echo $pair;! done
> -bash: syntax error near unexpected token `do'
> 
> san-svn:/var/lib/svn# for pair in `awk
> '/^[^[].+[^\n]$/ {print $1,
> $3}' passwd.fake`; do xargs "$pair" | echo; done
> 
> san-svn:/var/lib/svn# for pair in `awk
> '/^[^[].+[^\n]$/ {print $1,
> $3}' passwd.fake`; do xargs "$pair" | echo -; done
> -
> 
> 
> I did found the following work around :
> <<<
> san-svn:/var/lib/svn# for pair in `awk
> '/^[^[].+[^\n]$/ {print
> $1"_"$3}' passwd.fake`; do echo "$pair" | tr  _ ' '
> | cat; done
> user1 password1
> user2 password2
> >>>
> 
> But it's broken because "_" can be a valid character
> in a password /
> usernmae name and besides - I'd to find a smarter
> solution.
> 
> Any help / pokes to right direction would be highly
> appreciated.
> 
> Thank you,
> Maxim.
> 
> -- 
> Cheers,
> Maxim Vexler
> 
> "Free as in Freedom" - Do u GNU ?
> 
>
=================================================================
> To unsubscribe, send mail to
> [EMAIL PROTECTED] with
> the word "unsubscribe" in the message body, e.g.,
> run the command
> echo unsubscribe | mail
> [EMAIL PROTECTED]
> 
> 



 
____________________________________________________________________________________
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com

=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to