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< $1Shell 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