Shell Learning Note (1): Using IFS print users and default shell

Source: Internet
Author: User

Resources: Linux shell script Raiders author Sarath Lakshman People's post and telecommunications press

Shell: Reads the contents of each line of the file and outputs the notation 1

Purpose: Read the passwd file, get the user name and its default shell, and print it out

First cp/etc/passwd./PASSWD_CP
Shell script get_usr_shell.sh content is as follows:

#!/bin/BashfunctionGet_line_usr_shell () {#Echo$# Line=" $"oldifs=$IFS IFS=":"Count=0     forIteminch$line Do[$count-eq0] && user=$item [$count-eq6] && shell=$item Let Count++ DoneIFS=$oldIFSEcho$user \'s Shell is $shell}if[$#-GT1 ] Then    Echo "parameter is more one in main"Exit1fi whileRead Line Do#    Echo$line Get_line_usr_shell $line Done< $1
Shell Script

The results can then be obtained at the terminal input./get_usr_shell PASSWD_CP:

Shell Learning Note (1): Using IFS print users and default shell

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.