Find the answer to your Linux question:
Results 1 to 3 of 3
hi all i am a linux newbie. please tell me how this code works. 1st statement is clear to me. what does the while IFS statement do. what is IFS? ...
  1. #1
    Just Joined!
    Join Date
    Aug 2009
    Posts
    2

    table creation in linux

    hi all
    i am a linux newbie. please tell me how this code works.

    1st statement is clear to me. what does the while IFS statement do.
    what is IFS? read -r? un p uid gid j h s;?

    Also what does the last statement done</etc/passwd do??

    { printf "%-20s\t%s\t%s\t%s\n" "UserName" "UserID" "GroupID" "Home"
    while IFS=: read -r un p uid gid j h s;do
    printf "%-20s\t%d\t%d\t%s\n" "$un" "$uid" "$gid" "$h"
    done</etc/passwd;}

    Please reply .. just now trying to learn linux.. plz

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    I have moved this to a more appropriate forum.

    IFS stands for Internal Field Separator. Several things that you do in Bash take in a lot of input, but only give you one "chunk" at a time. The value of IFS determines what separates the "chunks" from one another.

    By default, the value of IFS is any whitespace. So a space, a tab, or a newline will separate each chunk.

    In the code you are asking about, IFS is being set to ":", which means to use a colon to separate chunks. The read command then reads its input to get seven different variables: $un, $p, $uid, etc.

    The last line uses I/O redirection to tell the loop that its standard input is coming from the file /etc/passwd instead of what it was before (by default the terminal, but could be something else based on how the script was executed).

    Does this make sense?
    DISTRO=Arch
    Registered Linux User #388732

  3. #3
    Just Joined!
    Join Date
    Aug 2009
    Posts
    2
    thanks Cabhan.

    Now its making sense. Later if i 've any doubts in linux, then i will raise it here. once again thanks..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...