Re: BASH + Best method of converting fields to variables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 07/16/2004 08:35 PM, Rick Stevens wrote:

Ow Mun Heng wrote:

Guys,

    Writing a batch_create_new_user script.
input is a file with this format

Username:Full Name:Default Group:Default Shell:Home Directory:Password
and the using those fields ($1 $2 $3 etc) and passing then to the useradd program


I'm having some trouble getting bash to get the positional fields into variables which I
can then plug into useradd


eg:
pseudo code
for each line in input file
  do
    username=$1
    name=$2
    useradd -c "$2" $1
  done

Can it be done using bash itself? (without calling awk)


Not really, because bash delimits fields with spaces, not colons.

Use cut with -d":" on each line to set the variables?



[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux