linux - 当我启动 bash 脚本时,如何找到 Ubuntu 中的所有用户并通过参数显示用户信息?

标签 linux bash ubuntu

我只知道一种解决方案 - 监视文件/etc/passwd 但我如何启动带有参数的脚本,例如像这样

./myscript user_name

并获取有关特定用户的信息?

我的脚本看起来像这样

grep home /etc/passwd | cut -d: -f1

但如果没有参数 - 显示系统中所有用户的信息

最佳答案

我希望您问的是如何将参数传递给 bash 脚本。 使用

./myscript user_name

并在脚本中将其访问为

username=$1

关于linux - 当我启动 bash 脚本时,如何找到 Ubuntu 中的所有用户并通过参数显示用户信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44870154/

相关文章:

linux - Git 找不到存储库

database - 在 Linux 上安装 Oracle 数据库

bash - Cron 作业未获取 .bashrc 中设置的环境变量

bash - 意外的 if 语句行为

python-3.x - 无法安装 matplotlib 也无法升级 pip

python - pip3 install isal 在 Ubuntu 18 中失败,但在 Ubuntu 20 中运行良好(dockerized 场景)

linux - Emacs 粘贴不起作用

linux - 如何使用 ftrace 仅跟踪系统调用事件而不显示 Linux 内核中的任何其他函数?

android - 在 Android 上使用 librtmp 编译 FFMPEG 时出现 "Undefined Reference"

linux - Bash、Shell、UXTerm 和终端之间的区别