⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 realname.sh

📁 Shall高级编程
💻 SH
字号:
#!/bin/bash# realname.sh## From username, gets "real name" from /etc/passwd.ARGCOUNT=1       # Expect one arg.E_WRONGARGS=65file=/etc/passwdpattern=$1if [ $# -ne "$ARGCOUNT" ]then  echo "Usage: `basename $0` USERNAME"  exit $E_WRONGARGSfi  file_excerpt ()  # Scan file for pattern, then print relevant portion of line.{while read line  # "while" does not necessarily need "[ condition ]"do  echo "$line" | grep $1 | awk -F":" '{ print $5 }'  # Have awk use ":" delimiter.done} <$file  # Redirect into function's stdin.file_excerpt $pattern# Yes, this entire script could be reduced to#       grep PATTERN /etc/passwd | awk -F":" '{ print $5 }'# or#       awk -F: '/PATTERN/ {print $5}'# or#       awk -F: '($1 == "username") { print $5 }' # real name from username# However, it might not be as instructive.exit 0

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -