Linux Script Command Help

jrustad24

New Member
Joined
Nov 14, 2020
Messages
4
Reaction score
0
Credits
43
I need the correct commands for "adding a blank line after my previous commands output" and "displaying a message on screen indicating the script is done running. For adding a blank line I've tried "echo" after the command but it doesn't work.
 


What have you tried? This seems to work:
Code:
#!/bin/bash

echo "Hello World!!"
echo
echo
echo "Hello World!!"
Otherwise you can give an example of what you are trying to do?
 
What have you tried? This seems to work:
Code:
#!/bin/bash

echo "Hello World!!"
echo
echo
echo "Hello World!!"
Otherwise you can give an example of what you are trying to do?
I'm trying to add a space (blank line) between the outputs as you see in the attachment. Attachment includes what I got vs what it should look like. Also, do you have a command for displaying a message. Thanks!
 

Attachments

  • Capture2.PNG
    Capture2.PNG
    21.5 KB · Views: 415
  • Capture3.PNG
    Capture3.PNG
    7.9 KB · Views: 393
Can you show us the exact commands you're using to get that output?
If we can see exactly what you're doing, we can offer a better solution to get a space between the two lines of output.
For example, is this just being displayed on screen when your script is ran? Or is the output from these commands being redirected to a file?

If it's being displayed on screen then it could be a case of something like this:
Bash:
command1
echo
command2
Where command1 is the command getting your first bit of output
command2 is your other command.
The empty echo command will just create an empty line between the output from the first command and the output of the second.

OR - If you're doing something like this and redirecting output:
Bash:
( command1 && command2 ) > /path/to/output-file

Then you could add space in the output like this:
Bash:
( command1 && echo && command2 ) > /path/to/file

Also re: "displaying a message on-screen indicating the script has finished":
Do you mean you want a message to appear in the terminal?
Or do you mean you want a notification dialog to appear on the desktop?

If you want to see a message in the terminal - it really depends on exactly what you're doing in your script, but again - depending on what you want - it could be as simple as using an echo command at the end of your script.
e.g.
Bash:
echo "Script $0 has finished!"
Where $0 is the name of your script.

If you want a notification, there are a number of options.
Off the top of my head notify-send comes immediately to mind.
notify-send should be in the repos of most linux distros - it's part of the libnotify package. It may even be installed by default.
To use notify-send in your script simply add this as the last line of your script:
Code:
notify-send "Script $0 - has finished!"
And that will pop up a notification on your desktop, in your notification area.

Or - you could install and use xmessage.
Again, xmessage should be in the repos of most distros.
At the end of your script you could add a line something like this:
Bash:
xmessage -timeout 2 -nearmouse "Script $0 has finished!"

And that will pop up a small dialog with an OK button and the message "$0 has finished!" near the mouse position. - Where $0 is the name of the script.
The timeout will cause the dialog to disappear after two seconds. Clicking the OK button before 2 seconds is up will also get rid of the dialog.
Feel free to play around with the options for xmessage.

There are probably a few other solutions for providing desktop notifications from scripts, but those two are the only ones that immediately spring to my mind!
 

Members online


Top