Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
0
rated 0 times [  0] [ 0]  / answers: 1 / hits: 1046  / 3 Years ago, tue, july 20, 2021, 9:24:08

I have a script file (start-conky.sh). It executes correctly, but when I do a "ps -u " it shows as still a PID, which I'm assuming means it is still in memory. Unless I do a "kill " it just stays there. It is not causing any problem. I'm just curious as to how to get the script to terminate after it executes. I've listed the script below. I really don't know that much about writing programs, so I'm sure there are mistakes. Can anyone help?



Title: start-conky.sh "the title is just listed here it is not in the script"



#!/bin/bash

conky -c ~/Conky/scripts/config1 & conky -c ~/Conky/scripts/config2

exit

More From » conky

 Answers
0

When a script is run, each line is executed one at a time and each must complete before the next one starts. The & character after a command launches the command in the background allowing the next statement to be executed immediately without waiting for the previous one to finish.



So, your script is launching one instance of conky in the background using the config1 file and then launching another instance of conky in the foreground using the config2 file and then waits for that instance to finish before processing the next exit line. If you change your script to have a & after each conky command like this...



#!/bin/bash

conky -c ~/Conky/scripts/config1 &
conky -c ~/Conky/scripts/config2 &

exit


...it will not wait for them to finish before processing the exit command.



As John and Eliah stated, && is used to chain two commands together with the second one executing only if the first one completed successfully. This is generally done from the command line as opposed to a script. This explains why after you made this change the second instance of conky never launched. The first one never finished so that the second could start.



I hope that clears some stuff up.


[#39239] Wednesday, July 21, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
anxietunnel

Total Points: 66
Total Questions: 120
Total Answers: 115

Location: Norway
Member since Sat, Mar 4, 2023
1 Year ago
;