Attempting to get this program to only print Usernames that are between 5 and 10 characters long [on hold]











up vote
-2
down vote

favorite












I have written a bash program that scans through /etc/passwd and prints out all of the usernames that are in the directory however i need the program to only print out usernames that are between 5 and 10 characters long.
I need to change it.



#!/bin/bash

MAXLENGTH=$(cut -d: -f1 < /etc/passwd | wc -L)
MINLENGTH=$MAXLENGTH
SMALLESTNAME=""

for NAME in $(cut -d: -f1 < /etc/passwd)
do
if [ ${#NAME} -eq $MAXLENGTH ]
then
echo "The Longest UserName In The System
Is:" $NAME
echo " Its Length Is" $MAXLENGTH
elif [ ${#NAME} -lt $MINLENGTH ]
then
MINLENGTH=${#NAME}
SMALLESTNAME=$NAME
fi

done

echo
echo "The Smallest UserName In The System Is:"
$SMALLESTNAME
echo "Its Length is:" $MINLENGTH









share|improve this question









New contributor




IDontKnowWhatImDoing is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by G-Man, RalfFriedl, Anthony Geoghegan, Stephen Harris, Thomas 2 days ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This question has been posted on multiple sites. Cross-posting is strongly discouraged; see the help center and community FAQ for more information." – Anthony Geoghegan, Stephen Harris, Thomas














  • Please don't cross-post: stackoverflow.com/q/53696947/1640661
    – Anthony Geoghegan
    2 days ago















up vote
-2
down vote

favorite












I have written a bash program that scans through /etc/passwd and prints out all of the usernames that are in the directory however i need the program to only print out usernames that are between 5 and 10 characters long.
I need to change it.



#!/bin/bash

MAXLENGTH=$(cut -d: -f1 < /etc/passwd | wc -L)
MINLENGTH=$MAXLENGTH
SMALLESTNAME=""

for NAME in $(cut -d: -f1 < /etc/passwd)
do
if [ ${#NAME} -eq $MAXLENGTH ]
then
echo "The Longest UserName In The System
Is:" $NAME
echo " Its Length Is" $MAXLENGTH
elif [ ${#NAME} -lt $MINLENGTH ]
then
MINLENGTH=${#NAME}
SMALLESTNAME=$NAME
fi

done

echo
echo "The Smallest UserName In The System Is:"
$SMALLESTNAME
echo "Its Length is:" $MINLENGTH









share|improve this question









New contributor




IDontKnowWhatImDoing is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by G-Man, RalfFriedl, Anthony Geoghegan, Stephen Harris, Thomas 2 days ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This question has been posted on multiple sites. Cross-posting is strongly discouraged; see the help center and community FAQ for more information." – Anthony Geoghegan, Stephen Harris, Thomas














  • Please don't cross-post: stackoverflow.com/q/53696947/1640661
    – Anthony Geoghegan
    2 days ago













up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











I have written a bash program that scans through /etc/passwd and prints out all of the usernames that are in the directory however i need the program to only print out usernames that are between 5 and 10 characters long.
I need to change it.



#!/bin/bash

MAXLENGTH=$(cut -d: -f1 < /etc/passwd | wc -L)
MINLENGTH=$MAXLENGTH
SMALLESTNAME=""

for NAME in $(cut -d: -f1 < /etc/passwd)
do
if [ ${#NAME} -eq $MAXLENGTH ]
then
echo "The Longest UserName In The System
Is:" $NAME
echo " Its Length Is" $MAXLENGTH
elif [ ${#NAME} -lt $MINLENGTH ]
then
MINLENGTH=${#NAME}
SMALLESTNAME=$NAME
fi

done

echo
echo "The Smallest UserName In The System Is:"
$SMALLESTNAME
echo "Its Length is:" $MINLENGTH









share|improve this question









New contributor




IDontKnowWhatImDoing is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I have written a bash program that scans through /etc/passwd and prints out all of the usernames that are in the directory however i need the program to only print out usernames that are between 5 and 10 characters long.
I need to change it.



#!/bin/bash

MAXLENGTH=$(cut -d: -f1 < /etc/passwd | wc -L)
MINLENGTH=$MAXLENGTH
SMALLESTNAME=""

for NAME in $(cut -d: -f1 < /etc/passwd)
do
if [ ${#NAME} -eq $MAXLENGTH ]
then
echo "The Longest UserName In The System
Is:" $NAME
echo " Its Length Is" $MAXLENGTH
elif [ ${#NAME} -lt $MINLENGTH ]
then
MINLENGTH=${#NAME}
SMALLESTNAME=$NAME
fi

done

echo
echo "The Smallest UserName In The System Is:"
$SMALLESTNAME
echo "Its Length is:" $MINLENGTH






bash shell-script shell






share|improve this question









New contributor




IDontKnowWhatImDoing is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




IDontKnowWhatImDoing is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 days ago









Rui F Ribeiro

38.5k1479128




38.5k1479128






New contributor




IDontKnowWhatImDoing is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









IDontKnowWhatImDoing

1




1




New contributor




IDontKnowWhatImDoing is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





IDontKnowWhatImDoing is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






IDontKnowWhatImDoing is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




put on hold as off-topic by G-Man, RalfFriedl, Anthony Geoghegan, Stephen Harris, Thomas 2 days ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This question has been posted on multiple sites. Cross-posting is strongly discouraged; see the help center and community FAQ for more information." – Anthony Geoghegan, Stephen Harris, Thomas





put on hold as off-topic by G-Man, RalfFriedl, Anthony Geoghegan, Stephen Harris, Thomas 2 days ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This question has been posted on multiple sites. Cross-posting is strongly discouraged; see the help center and community FAQ for more information." – Anthony Geoghegan, Stephen Harris, Thomas













  • Please don't cross-post: stackoverflow.com/q/53696947/1640661
    – Anthony Geoghegan
    2 days ago


















  • Please don't cross-post: stackoverflow.com/q/53696947/1640661
    – Anthony Geoghegan
    2 days ago
















Please don't cross-post: stackoverflow.com/q/53696947/1640661
– Anthony Geoghegan
2 days ago




Please don't cross-post: stackoverflow.com/q/53696947/1640661
– Anthony Geoghegan
2 days ago










4 Answers
4






active

oldest

votes

















up vote
3
down vote













getent passwd | awk -F : 'length($1) >= 5 && length($1) <= 10 { print $1 }'


This will print the usernames that are between 5 and 10 characters long (inclusively).



For the shortest and longest names:



getent passwd |
awk -F : 's == "" || length($1) < length(s) { s = $1 }
l == "" || length($1) > length(l) { l = $1 }
END { printf("shortest: %s (%d chars)n", s, length(s))
printf("longest: %s (%d chars)n", l, length(l)) }'


Doing both things with a single pass over the password database (as a complete bash script, although /bin/sh should have been far more than enough since this script does not use anything bash specific, any shell would be able to run it):



#!/bin/bash
getent passwd |
awk -F : 'length($1) >= 5 && length($1) <= 10 { print $1 }
s == "" || length($1) < length(s) { s = $1 }
l == "" || length($1) > length(l) { l = $1 }
END { printf("shortest: %s (%d chars)n", s, length(s))
printf("longest: %s (%d chars)n", l, length(l)) }'





share|improve this answer























  • would i put that in my already created program or on its own??
    – IDontKnowWhatImDoing
    2 days ago






  • 1




    @IDontKnowWhatImDoing On its own.
    – Kusalananda
    2 days ago










  • yes well . tried that however it prints allot of extra things aswell i only need it to print out the username eg. dvc18rkb:*:156726:513:Development Language Disorders Conf Off:/homedir/dvc18rkb:/bin/tcsh where i just need the 'dvc18rkb"
    – IDontKnowWhatImDoing
    2 days ago








  • 1




    @IDontKnowWhatImDoing Fixed now.
    – Kusalananda
    2 days ago










  • this now works, is there a way to implement it into my original code as i need to keep it all as a bash file and to print the smallest and largest name at the same time?
    – IDontKnowWhatImDoing
    2 days ago


















up vote
1
down vote













Impractical but somewhat mesmerizing: bash extended file patterns:



shopt -s extglob

getent passwd |
cut -d: -f1 |
while IFS= read -r name; do
[[ $name == ?????@(|?|??|???|????|?????) ]] && echo "$name"
done





share|improve this answer




























    up vote
    0
    down vote













    Here's your homework solution:



    #!/bin/bash
    for NAME in $(cut -d: -f1 < /etc/passwd)
    do
    if [[ ${#NAME} -gt 10 || ${#NAME} -lt 5 ]]
    then
    continue
    else
    echo "Username in the system is: $NAME"
    echo "Its length Is ${#NAME}"
    fi
    done


    You're welcome.






    share|improve this answer








    New contributor




    Dougie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.














    • 1




      Would be worth full marks if you used a while-read loop reading from getent passwd instead. Using a for loop over a command substitution is distinctly inelegant. Also, it seems as if the user still wants to do the max/min calculation. Also, what's with the continue? Can't you just test for the inverse logical condition and skip the empty then-else branch?
      – Kusalananda
      2 days ago












    • Thanks but its not homework
      – IDontKnowWhatImDoing
      2 days ago






    • 2




      @IDontKnowWhatImDoing Show me some task that requires you to do this kind of operation on usernames that is not homework...
      – Kusalananda
      2 days ago










    • @kusalananda it's pure unadulterated hacking of the original. Hence the inelegance.
      – Dougie
      2 days ago










    • @Dougie also this does not print put all of the user names that are between 5 and 10 charactersonly the longest and shortest i need to print out all usernames
      – IDontKnowWhatImDoing
      2 days ago


















    up vote
    0
    down vote













    For a little more variety, cut and grep:



    getent passwd | cut -d: -f1 | grep -Ex '.{5,10}'


    This retrieves the passwd entries, cuts out the first field (username), then asks grep for an Extended regular expression match that spans the entire line (-x) where there are between 5 and 10 of any character (.).






    share|improve this answer




























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      3
      down vote













      getent passwd | awk -F : 'length($1) >= 5 && length($1) <= 10 { print $1 }'


      This will print the usernames that are between 5 and 10 characters long (inclusively).



      For the shortest and longest names:



      getent passwd |
      awk -F : 's == "" || length($1) < length(s) { s = $1 }
      l == "" || length($1) > length(l) { l = $1 }
      END { printf("shortest: %s (%d chars)n", s, length(s))
      printf("longest: %s (%d chars)n", l, length(l)) }'


      Doing both things with a single pass over the password database (as a complete bash script, although /bin/sh should have been far more than enough since this script does not use anything bash specific, any shell would be able to run it):



      #!/bin/bash
      getent passwd |
      awk -F : 'length($1) >= 5 && length($1) <= 10 { print $1 }
      s == "" || length($1) < length(s) { s = $1 }
      l == "" || length($1) > length(l) { l = $1 }
      END { printf("shortest: %s (%d chars)n", s, length(s))
      printf("longest: %s (%d chars)n", l, length(l)) }'





      share|improve this answer























      • would i put that in my already created program or on its own??
        – IDontKnowWhatImDoing
        2 days ago






      • 1




        @IDontKnowWhatImDoing On its own.
        – Kusalananda
        2 days ago










      • yes well . tried that however it prints allot of extra things aswell i only need it to print out the username eg. dvc18rkb:*:156726:513:Development Language Disorders Conf Off:/homedir/dvc18rkb:/bin/tcsh where i just need the 'dvc18rkb"
        – IDontKnowWhatImDoing
        2 days ago








      • 1




        @IDontKnowWhatImDoing Fixed now.
        – Kusalananda
        2 days ago










      • this now works, is there a way to implement it into my original code as i need to keep it all as a bash file and to print the smallest and largest name at the same time?
        – IDontKnowWhatImDoing
        2 days ago















      up vote
      3
      down vote













      getent passwd | awk -F : 'length($1) >= 5 && length($1) <= 10 { print $1 }'


      This will print the usernames that are between 5 and 10 characters long (inclusively).



      For the shortest and longest names:



      getent passwd |
      awk -F : 's == "" || length($1) < length(s) { s = $1 }
      l == "" || length($1) > length(l) { l = $1 }
      END { printf("shortest: %s (%d chars)n", s, length(s))
      printf("longest: %s (%d chars)n", l, length(l)) }'


      Doing both things with a single pass over the password database (as a complete bash script, although /bin/sh should have been far more than enough since this script does not use anything bash specific, any shell would be able to run it):



      #!/bin/bash
      getent passwd |
      awk -F : 'length($1) >= 5 && length($1) <= 10 { print $1 }
      s == "" || length($1) < length(s) { s = $1 }
      l == "" || length($1) > length(l) { l = $1 }
      END { printf("shortest: %s (%d chars)n", s, length(s))
      printf("longest: %s (%d chars)n", l, length(l)) }'





      share|improve this answer























      • would i put that in my already created program or on its own??
        – IDontKnowWhatImDoing
        2 days ago






      • 1




        @IDontKnowWhatImDoing On its own.
        – Kusalananda
        2 days ago










      • yes well . tried that however it prints allot of extra things aswell i only need it to print out the username eg. dvc18rkb:*:156726:513:Development Language Disorders Conf Off:/homedir/dvc18rkb:/bin/tcsh where i just need the 'dvc18rkb"
        – IDontKnowWhatImDoing
        2 days ago








      • 1




        @IDontKnowWhatImDoing Fixed now.
        – Kusalananda
        2 days ago










      • this now works, is there a way to implement it into my original code as i need to keep it all as a bash file and to print the smallest and largest name at the same time?
        – IDontKnowWhatImDoing
        2 days ago













      up vote
      3
      down vote










      up vote
      3
      down vote









      getent passwd | awk -F : 'length($1) >= 5 && length($1) <= 10 { print $1 }'


      This will print the usernames that are between 5 and 10 characters long (inclusively).



      For the shortest and longest names:



      getent passwd |
      awk -F : 's == "" || length($1) < length(s) { s = $1 }
      l == "" || length($1) > length(l) { l = $1 }
      END { printf("shortest: %s (%d chars)n", s, length(s))
      printf("longest: %s (%d chars)n", l, length(l)) }'


      Doing both things with a single pass over the password database (as a complete bash script, although /bin/sh should have been far more than enough since this script does not use anything bash specific, any shell would be able to run it):



      #!/bin/bash
      getent passwd |
      awk -F : 'length($1) >= 5 && length($1) <= 10 { print $1 }
      s == "" || length($1) < length(s) { s = $1 }
      l == "" || length($1) > length(l) { l = $1 }
      END { printf("shortest: %s (%d chars)n", s, length(s))
      printf("longest: %s (%d chars)n", l, length(l)) }'





      share|improve this answer














      getent passwd | awk -F : 'length($1) >= 5 && length($1) <= 10 { print $1 }'


      This will print the usernames that are between 5 and 10 characters long (inclusively).



      For the shortest and longest names:



      getent passwd |
      awk -F : 's == "" || length($1) < length(s) { s = $1 }
      l == "" || length($1) > length(l) { l = $1 }
      END { printf("shortest: %s (%d chars)n", s, length(s))
      printf("longest: %s (%d chars)n", l, length(l)) }'


      Doing both things with a single pass over the password database (as a complete bash script, although /bin/sh should have been far more than enough since this script does not use anything bash specific, any shell would be able to run it):



      #!/bin/bash
      getent passwd |
      awk -F : 'length($1) >= 5 && length($1) <= 10 { print $1 }
      s == "" || length($1) < length(s) { s = $1 }
      l == "" || length($1) > length(l) { l = $1 }
      END { printf("shortest: %s (%d chars)n", s, length(s))
      printf("longest: %s (%d chars)n", l, length(l)) }'






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited 2 days ago

























      answered 2 days ago









      Kusalananda

      119k16225367




      119k16225367












      • would i put that in my already created program or on its own??
        – IDontKnowWhatImDoing
        2 days ago






      • 1




        @IDontKnowWhatImDoing On its own.
        – Kusalananda
        2 days ago










      • yes well . tried that however it prints allot of extra things aswell i only need it to print out the username eg. dvc18rkb:*:156726:513:Development Language Disorders Conf Off:/homedir/dvc18rkb:/bin/tcsh where i just need the 'dvc18rkb"
        – IDontKnowWhatImDoing
        2 days ago








      • 1




        @IDontKnowWhatImDoing Fixed now.
        – Kusalananda
        2 days ago










      • this now works, is there a way to implement it into my original code as i need to keep it all as a bash file and to print the smallest and largest name at the same time?
        – IDontKnowWhatImDoing
        2 days ago


















      • would i put that in my already created program or on its own??
        – IDontKnowWhatImDoing
        2 days ago






      • 1




        @IDontKnowWhatImDoing On its own.
        – Kusalananda
        2 days ago










      • yes well . tried that however it prints allot of extra things aswell i only need it to print out the username eg. dvc18rkb:*:156726:513:Development Language Disorders Conf Off:/homedir/dvc18rkb:/bin/tcsh where i just need the 'dvc18rkb"
        – IDontKnowWhatImDoing
        2 days ago








      • 1




        @IDontKnowWhatImDoing Fixed now.
        – Kusalananda
        2 days ago










      • this now works, is there a way to implement it into my original code as i need to keep it all as a bash file and to print the smallest and largest name at the same time?
        – IDontKnowWhatImDoing
        2 days ago
















      would i put that in my already created program or on its own??
      – IDontKnowWhatImDoing
      2 days ago




      would i put that in my already created program or on its own??
      – IDontKnowWhatImDoing
      2 days ago




      1




      1




      @IDontKnowWhatImDoing On its own.
      – Kusalananda
      2 days ago




      @IDontKnowWhatImDoing On its own.
      – Kusalananda
      2 days ago












      yes well . tried that however it prints allot of extra things aswell i only need it to print out the username eg. dvc18rkb:*:156726:513:Development Language Disorders Conf Off:/homedir/dvc18rkb:/bin/tcsh where i just need the 'dvc18rkb"
      – IDontKnowWhatImDoing
      2 days ago






      yes well . tried that however it prints allot of extra things aswell i only need it to print out the username eg. dvc18rkb:*:156726:513:Development Language Disorders Conf Off:/homedir/dvc18rkb:/bin/tcsh where i just need the 'dvc18rkb"
      – IDontKnowWhatImDoing
      2 days ago






      1




      1




      @IDontKnowWhatImDoing Fixed now.
      – Kusalananda
      2 days ago




      @IDontKnowWhatImDoing Fixed now.
      – Kusalananda
      2 days ago












      this now works, is there a way to implement it into my original code as i need to keep it all as a bash file and to print the smallest and largest name at the same time?
      – IDontKnowWhatImDoing
      2 days ago




      this now works, is there a way to implement it into my original code as i need to keep it all as a bash file and to print the smallest and largest name at the same time?
      – IDontKnowWhatImDoing
      2 days ago












      up vote
      1
      down vote













      Impractical but somewhat mesmerizing: bash extended file patterns:



      shopt -s extglob

      getent passwd |
      cut -d: -f1 |
      while IFS= read -r name; do
      [[ $name == ?????@(|?|??|???|????|?????) ]] && echo "$name"
      done





      share|improve this answer

























        up vote
        1
        down vote













        Impractical but somewhat mesmerizing: bash extended file patterns:



        shopt -s extglob

        getent passwd |
        cut -d: -f1 |
        while IFS= read -r name; do
        [[ $name == ?????@(|?|??|???|????|?????) ]] && echo "$name"
        done





        share|improve this answer























          up vote
          1
          down vote










          up vote
          1
          down vote









          Impractical but somewhat mesmerizing: bash extended file patterns:



          shopt -s extglob

          getent passwd |
          cut -d: -f1 |
          while IFS= read -r name; do
          [[ $name == ?????@(|?|??|???|????|?????) ]] && echo "$name"
          done





          share|improve this answer












          Impractical but somewhat mesmerizing: bash extended file patterns:



          shopt -s extglob

          getent passwd |
          cut -d: -f1 |
          while IFS= read -r name; do
          [[ $name == ?????@(|?|??|???|????|?????) ]] && echo "$name"
          done






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 2 days ago









          glenn jackman

          50k569106




          50k569106






















              up vote
              0
              down vote













              Here's your homework solution:



              #!/bin/bash
              for NAME in $(cut -d: -f1 < /etc/passwd)
              do
              if [[ ${#NAME} -gt 10 || ${#NAME} -lt 5 ]]
              then
              continue
              else
              echo "Username in the system is: $NAME"
              echo "Its length Is ${#NAME}"
              fi
              done


              You're welcome.






              share|improve this answer








              New contributor




              Dougie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.














              • 1




                Would be worth full marks if you used a while-read loop reading from getent passwd instead. Using a for loop over a command substitution is distinctly inelegant. Also, it seems as if the user still wants to do the max/min calculation. Also, what's with the continue? Can't you just test for the inverse logical condition and skip the empty then-else branch?
                – Kusalananda
                2 days ago












              • Thanks but its not homework
                – IDontKnowWhatImDoing
                2 days ago






              • 2




                @IDontKnowWhatImDoing Show me some task that requires you to do this kind of operation on usernames that is not homework...
                – Kusalananda
                2 days ago










              • @kusalananda it's pure unadulterated hacking of the original. Hence the inelegance.
                – Dougie
                2 days ago










              • @Dougie also this does not print put all of the user names that are between 5 and 10 charactersonly the longest and shortest i need to print out all usernames
                – IDontKnowWhatImDoing
                2 days ago















              up vote
              0
              down vote













              Here's your homework solution:



              #!/bin/bash
              for NAME in $(cut -d: -f1 < /etc/passwd)
              do
              if [[ ${#NAME} -gt 10 || ${#NAME} -lt 5 ]]
              then
              continue
              else
              echo "Username in the system is: $NAME"
              echo "Its length Is ${#NAME}"
              fi
              done


              You're welcome.






              share|improve this answer








              New contributor




              Dougie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.














              • 1




                Would be worth full marks if you used a while-read loop reading from getent passwd instead. Using a for loop over a command substitution is distinctly inelegant. Also, it seems as if the user still wants to do the max/min calculation. Also, what's with the continue? Can't you just test for the inverse logical condition and skip the empty then-else branch?
                – Kusalananda
                2 days ago












              • Thanks but its not homework
                – IDontKnowWhatImDoing
                2 days ago






              • 2




                @IDontKnowWhatImDoing Show me some task that requires you to do this kind of operation on usernames that is not homework...
                – Kusalananda
                2 days ago










              • @kusalananda it's pure unadulterated hacking of the original. Hence the inelegance.
                – Dougie
                2 days ago










              • @Dougie also this does not print put all of the user names that are between 5 and 10 charactersonly the longest and shortest i need to print out all usernames
                – IDontKnowWhatImDoing
                2 days ago













              up vote
              0
              down vote










              up vote
              0
              down vote









              Here's your homework solution:



              #!/bin/bash
              for NAME in $(cut -d: -f1 < /etc/passwd)
              do
              if [[ ${#NAME} -gt 10 || ${#NAME} -lt 5 ]]
              then
              continue
              else
              echo "Username in the system is: $NAME"
              echo "Its length Is ${#NAME}"
              fi
              done


              You're welcome.






              share|improve this answer








              New contributor




              Dougie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.









              Here's your homework solution:



              #!/bin/bash
              for NAME in $(cut -d: -f1 < /etc/passwd)
              do
              if [[ ${#NAME} -gt 10 || ${#NAME} -lt 5 ]]
              then
              continue
              else
              echo "Username in the system is: $NAME"
              echo "Its length Is ${#NAME}"
              fi
              done


              You're welcome.







              share|improve this answer








              New contributor




              Dougie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.









              share|improve this answer



              share|improve this answer






              New contributor




              Dougie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.









              answered 2 days ago









              Dougie

              1014




              1014




              New contributor




              Dougie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.





              New contributor





              Dougie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.






              Dougie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.








              • 1




                Would be worth full marks if you used a while-read loop reading from getent passwd instead. Using a for loop over a command substitution is distinctly inelegant. Also, it seems as if the user still wants to do the max/min calculation. Also, what's with the continue? Can't you just test for the inverse logical condition and skip the empty then-else branch?
                – Kusalananda
                2 days ago












              • Thanks but its not homework
                – IDontKnowWhatImDoing
                2 days ago






              • 2




                @IDontKnowWhatImDoing Show me some task that requires you to do this kind of operation on usernames that is not homework...
                – Kusalananda
                2 days ago










              • @kusalananda it's pure unadulterated hacking of the original. Hence the inelegance.
                – Dougie
                2 days ago










              • @Dougie also this does not print put all of the user names that are between 5 and 10 charactersonly the longest and shortest i need to print out all usernames
                – IDontKnowWhatImDoing
                2 days ago














              • 1




                Would be worth full marks if you used a while-read loop reading from getent passwd instead. Using a for loop over a command substitution is distinctly inelegant. Also, it seems as if the user still wants to do the max/min calculation. Also, what's with the continue? Can't you just test for the inverse logical condition and skip the empty then-else branch?
                – Kusalananda
                2 days ago












              • Thanks but its not homework
                – IDontKnowWhatImDoing
                2 days ago






              • 2




                @IDontKnowWhatImDoing Show me some task that requires you to do this kind of operation on usernames that is not homework...
                – Kusalananda
                2 days ago










              • @kusalananda it's pure unadulterated hacking of the original. Hence the inelegance.
                – Dougie
                2 days ago










              • @Dougie also this does not print put all of the user names that are between 5 and 10 charactersonly the longest and shortest i need to print out all usernames
                – IDontKnowWhatImDoing
                2 days ago








              1




              1




              Would be worth full marks if you used a while-read loop reading from getent passwd instead. Using a for loop over a command substitution is distinctly inelegant. Also, it seems as if the user still wants to do the max/min calculation. Also, what's with the continue? Can't you just test for the inverse logical condition and skip the empty then-else branch?
              – Kusalananda
              2 days ago






              Would be worth full marks if you used a while-read loop reading from getent passwd instead. Using a for loop over a command substitution is distinctly inelegant. Also, it seems as if the user still wants to do the max/min calculation. Also, what's with the continue? Can't you just test for the inverse logical condition and skip the empty then-else branch?
              – Kusalananda
              2 days ago














              Thanks but its not homework
              – IDontKnowWhatImDoing
              2 days ago




              Thanks but its not homework
              – IDontKnowWhatImDoing
              2 days ago




              2




              2




              @IDontKnowWhatImDoing Show me some task that requires you to do this kind of operation on usernames that is not homework...
              – Kusalananda
              2 days ago




              @IDontKnowWhatImDoing Show me some task that requires you to do this kind of operation on usernames that is not homework...
              – Kusalananda
              2 days ago












              @kusalananda it's pure unadulterated hacking of the original. Hence the inelegance.
              – Dougie
              2 days ago




              @kusalananda it's pure unadulterated hacking of the original. Hence the inelegance.
              – Dougie
              2 days ago












              @Dougie also this does not print put all of the user names that are between 5 and 10 charactersonly the longest and shortest i need to print out all usernames
              – IDontKnowWhatImDoing
              2 days ago




              @Dougie also this does not print put all of the user names that are between 5 and 10 charactersonly the longest and shortest i need to print out all usernames
              – IDontKnowWhatImDoing
              2 days ago










              up vote
              0
              down vote













              For a little more variety, cut and grep:



              getent passwd | cut -d: -f1 | grep -Ex '.{5,10}'


              This retrieves the passwd entries, cuts out the first field (username), then asks grep for an Extended regular expression match that spans the entire line (-x) where there are between 5 and 10 of any character (.).






              share|improve this answer

























                up vote
                0
                down vote













                For a little more variety, cut and grep:



                getent passwd | cut -d: -f1 | grep -Ex '.{5,10}'


                This retrieves the passwd entries, cuts out the first field (username), then asks grep for an Extended regular expression match that spans the entire line (-x) where there are between 5 and 10 of any character (.).






                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  For a little more variety, cut and grep:



                  getent passwd | cut -d: -f1 | grep -Ex '.{5,10}'


                  This retrieves the passwd entries, cuts out the first field (username), then asks grep for an Extended regular expression match that spans the entire line (-x) where there are between 5 and 10 of any character (.).






                  share|improve this answer












                  For a little more variety, cut and grep:



                  getent passwd | cut -d: -f1 | grep -Ex '.{5,10}'


                  This retrieves the passwd entries, cuts out the first field (username), then asks grep for an Extended regular expression match that spans the entire line (-x) where there are between 5 and 10 of any character (.).







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 2 days ago









                  Jeff Schaller

                  37.6k1052121




                  37.6k1052121















                      Popular posts from this blog

                      Accessing regular linux commands in Huawei's Dopra Linux

                      Can't connect RFCOMM socket: Host is down

                      Kernel panic - not syncing: Fatal Exception in Interrupt