#!/bin/bash # read-ifs: read fields from a file FILE=/etc/passwd read -p "Enter a user name > " user_name file_info=$(grep "^$user_name:"$FILE) if [ -n "$file_info" ]; then IFS=":"read user pw uid gid name home shell <<< "$file_info" echo"User = '$user'" echo"UID = '$uid'" echo"GID = '$gid'" echo"Full Name = '$name'" echo"Home Dir. = '$home'" echo"Shell = '$shell'" else echo"No such user '$user_name'" >&2 exit 1 fi
#!/bin/bash # read-menu: a menu driven system information program clear echo" Please Select: 1. Display System Information 2. Display Disk Space 3. Display Home Space Utilization 0. Quit " read -p "Enter selection [0-3] > "
if [[ $REPLY =~ ^[0-3]$ ]]; then if [[ $REPLY == 0 ]]; then echo"Program terminated." exit fi if [[ $REPLY == 1 ]]; then echo"Hostname: $HOSTNAME" uptime exit fi if [[ $REPLY == 2 ]]; then df -h exit fi if [[ $REPLY == 3 ]]; then if [[ $(id -u) -eq 0 ]]; then echo"Home Space Utilization (All Users)" du -sh /home/* else echo"Home Space Utilization ($USER)" du -sh $HOME fi exit fi else echo"Invalid entry." >&2 exit 1 fi