Find the answer to your Linux question:
Results 1 to 4 of 4
hi i m iterating /etc/shadow file now i want to pick the second field which is a wild card "*" or encrypted password i m using a simple for loop ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2005
    Posts
    6

    print a wildcard


    hi
    i m iterating /etc/shadow file
    now i want to pick the second field which is a wild card "*" or encrypted password i m using a simple for loop

    #/bin/sh

    for WHO in `awk -F":" '{print $2}' /etc/shadow` ; do
    echo "$WHO"
    echo ${WHO}
    done
    i m just wants to print if it is a "*" then
    it should be * but it prints out the files in that directory becoz by default echo "*"
    will list files.is there any way i can print
    "*"
    root:$1$Kij0PSF0$b8zSNlahpjmC1wlqA6seZ1:12868:0::: ::
    bin:*:9797:0:::::
    daemon:*:9797:0:::::
    adm:*:9797:0:::::
    lp:*:9797:0:::::
    sync:*:9797:0:::::
    shutdown:*:9797:0:::::
    halt:*:9797:0:::::
    mail:*:9797:0:::::
    news:*:9797:0:::::
    uucp:*:9797:0:::::
    operator:*:9797:0:::::

  2. #2
    Linux Enthusiast
    Join Date
    Jan 2005
    Posts
    575
    Why do you have echo "$WHO" and right under it echo ${WHO} ?
    Anyway the first line gives you the answer for the second: it should be
    echo "${WHO}"

  3. #3
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    It will pay you to learn the subtleties of shell quoting and special characters. man bash will tell you more than you need to know.

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Newbie
    Join Date
    Mar 2005
    Location
    Bangalore, INDIA
    Posts
    122
    generally when u wanna print a wildcard we supress its meaning using
    a \
    try
    Code:
    echo *
    and 
    echo \*
    now if it gets a liitle cocky when u wann print ***
    u would have to use
    Code:
    echo \*\*\*
    to avoid this we use
    Code:
    echo '***'
    these quotes insulates everything inside them
    u can use double quotes for most of ur work........
    note:- double quotes insulates the meaning of everthing
    except
    1]double quotes itsel
    2]$
    3]` `

    also
    anything in the above quotes will be evaluated by the shell
    eg :- see
    Code:
    echo ` ls`
    and
    Code:
    echo ls


    i think thats all about quoting
    Portability is for people who cannot programme

Posting Permissions

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