【问题标题】:Why are my bash commands in notepad++ not printing in the command prompt? [duplicate]为什么我在 notepad++ 中的 bash 命令没有在命令提示符中打印? [复制]
【发布时间】:2020-08-27 22:33:55
【问题描述】:

我是编写 bash 文件以打开虚拟命令提示符的新手。我一直在尝试打印用户名、当前日期以及当前在我的计算机上运行进程的所有用户的列表。我一直在使用记事本++。错误发生在

whoami="$users" 
echo 'Good day to you,' "{$users}"

通过打印{ } 并使用

echo 'These are a list of users who are currently running processors on this computer: '
echo "{$ps}"

这也打印{ }。我需要做什么才能让这些正确打印?

【问题讨论】:

  • 请不要将代码和文本输出作为图像或图像链接发布 - reasoning。将其作为格式化文本复制到问题中。
  • 需要$() 才能运行命令并捕获其输出。那是$(users)$(ps)
  • $users$ps 是需要设置才能使用它们的变量。
  • 你期望whoami="$users"如何获取用户名?
  • 如果你分配变量whoami,你为什么要打印$users

标签: linux bash windows-subsystem-for-linux


【解决方案1】:

你可以这样试试。

#Set current user
user=$(whoami);
echo 'Good day to you,' $user

#Set Date
current_date=$(date);
echo 'Today is ,' $current_date

echo 'These are a list of users who are currently running processes on this computer'

echo $(ps -A)

【讨论】:

    猜你喜欢
    • 2020-07-11
    • 1970-01-01
    • 2016-04-18
    • 1970-01-01
    • 2020-02-26
    • 2022-06-20
    • 1970-01-01
    • 2019-01-02
    • 2020-11-07
    相关资源
    最近更新 更多