[SOLVED] launcher commands issue

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
User avatar
Big Kev
Level 1
Level 1
Posts: 5
Joined: Sat May 27, 2023 7:04 am

[SOLVED] launcher commands issue

Post by Big Kev »

Hello all I am a new user , installed linux due to lack of space to upgrade windows. i wish i had made the move years ago.
i am running the following -

Operating System: Linux Mint 21.1
Kernel: Linux 5.15.0-72-generic
Architecture: x86-64
Hardware Vendor: HP
Hardware Model: HP Stream Notebook

i want to run a launcher to automatically check and update my system and have got this far -

sh -c 'sudo apt update && sudo apt upgrade && $ echo "Finished"'

it will run the update and upgrade sections work correctly but it then closes terminal and I am never able to see if it has completed properly.

Can anyone point me in the right direction please
Last edited by LockBot on Mon Nov 27, 2023 11:00 pm, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: launcher commands issue

Post by rene »

There's an extraneous $ there which I'll assume is a typo/copypaste-o. I'll also assume you have the launcher set to "execute in terminal" (detailed formulation is desktop environment specific), and I'd recommend to just use the standard Upgrade Manager instead -- but a direct answer is stringing a read onto your command:

Code: Select all

sh -c 'sudo apt update && sudo apt upgrade; read -p "Finished " tmp'
This waits for <enter> to close the terminal.

And since you're new: this might also be a good time to mention that on Debian/Ubuntu/Mint /bin/sh is dash rather than bash, which is to say that if you ever want/need to use a bash-specific construct you need to explicitly say bash -c '...'. Here it doesn't matter (although bash has slightly nicer syntax for read that doesn't need the tmp throw-away variable).
User avatar
Termy
Level 12
Level 12
Posts: 4248
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: launcher commands issue

Post by Termy »

Big Kev wrote: Sat May 27, 2023 7:49 am [...]
Some terminal emulators have a flag which prevents this behavior, but failing that, you can:

Code: Select all

sh -c 'sudo apt update && sudo apt upgrade; echo "Press Enter to continue... "; read _'
I removed the lone $, as it'd almost certainly result in a 'command not found' error. I've also adjusted the logic, because you presumably want the prompt to display regardless of the status of the previous command. Both && and || are logical operators for AND and OR, respectively, while ; essentially acts as a new line.

This is why the following is a common convention for an if statement:

Code: Select all

if LIST; then
	LIST
fi
While the by-the-book approach is:

Code: Select all

if LIST
then
	LIST
fi
It's OK if you're not familiar with this stuff, but understanding ;, &&, and || will help a lot.

Below, Command_B will execute regardless of the success of the previous command.

Code: Select all

Command_A; Command_B
This logical AND operator means Command_B will execute only if Command_A succeeded.

Code: Select all

Command_A && Command_B
This logical OR operator means Command_B will only execute if Command_A fails.

Code: Select all

Command_A || Command_B
In Linux, every process can exit with a status of 0-255, where 0 is success and anything above usually indicates a failure of some sort. Some of these have special meanings, such as 130 for processes interrupted via SIGINT (interrupt signal), 127 for command not found, and 255 for an out of range exit status.

Lastly, you might prefer:

Code: Select all

sudo sh -c 'apt update && apt upgrade; echo "Press Enter to continue... "; read _'
I'm also Terminalforlife on GitHub.
User avatar
Big Kev
Level 1
Level 1
Posts: 5
Joined: Sat May 27, 2023 7:04 am

Re: launcher commands issue

Post by Big Kev »

thank you

everything is good now

I appreciate the help
Locked

Return to “Scripts & Bash”