Bash – Passing variables problem – Bash

awkbashscriptingsudo

I have a following problem:

#!/bin/bash
NUM=`cat accounts | wc -l`;
for i in {1..$NUM}
do
   account=`awk "NR==$i" accounts`;
    echo -e "\nAccount: $account\n";
  sudo ./backup_maildir $account;
done

"accounts" is a file with regular e-mail addresses, one in each line.
backup_maildir is expect script.

When the main script is executed, the 6th line successfuly echo current mail address, but the following line is not passing that string to backup_maildir script. If the $account variable is user@domain.com, a string that is passed to backup_maildir is {user@domain.com?} ?! How is that possible? How to solve it?

Best Answer

huh what a crazy script :) lets try like this :)

#!/bin/bash 
cat accounts | while read account 
do
    echo -e "\n Account: $account \n";
    echo sudo ./backup_maildir  "$account"; 
done

if everything looks fine and sudo line works out of script as expected drop the echo and voila