0

I am new at writing bash files to open into the virtual command prompt. I have been trying to print the username, current date, and a list of all users currently running processes on my computer. I have been using notepad++. The error occurs in the

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

by printing { } and also with the

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

This also prints { }. What do I need to do to allow these to print correctly?

NotePad++ code image

Results in the command promt

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Please do not post code and text output as images or links to images - [reasoning](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-on-so-when-asking-a-question). Copy it as formatted text into the question. – kaylum Aug 27 '20 at 22:34
  • Need to do `$()` to run a command and capture its output. That is `$(users)` and `$(ps)`. – kaylum Aug 27 '20 at 22:38
  • `$users` and `$ps` are variables that need to be set before you can use them. – Barmar Aug 27 '20 at 23:01
  • How do you expect `whoami="$users"` to get the user's name? – Barmar Aug 27 '20 at 23:04
  • And if you're assigning the variable `whoami`, why are you printing `$users`? – Barmar Aug 27 '20 at 23:05
  • You seem to understand how to set a variable to the output of a command, since you did it correctly for `$now`. You should do the same things for your other variables. – Barmar Aug 27 '20 at 23:06
  • I don't understand how this is related to Notepad++. Are you run the _bash_ window using the "Run" command of Notepad++ (F5)? In any case, your screenshot says that your variables `users` and `now` are not set. You need to put them into the environment before running the script. – user1934428 Aug 28 '20 at 06:21

1 Answers1

1

You can try like this.

#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)
Fatih Şennik
  • 1,295
  • 5
  • 12