Simple Bash Script

Quick to answer questions about finding your way around Linux Mint as a new user.
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
gary.zw

Simple Bash Script

Post by gary.zw »

I'm trying to write a simple Script to install a program--I know you can add it in terminal but I wanted to try with a script to see how it is done. I have the following so far which opens the terminal and but will not go on the the commands. If I create a launcher it works but i wanted to be able to click on the script directly and have I have it bring up the terminal and then execute the commands. Thanks for the help

Code: Select all

#!/bin/bash
xfce4-terminal
sudo add-apt-repository ppa:Repository
sudo apt-get update
sudo apt-get install package
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
WharfRat

Re: Simple Bash Script

Post by WharfRat »

You might try switching to the terminal you just opened with wmctrl. You can get the list of open windows with

Code: Select all

wmctrl -l 
Open few apps and run this to get an idea of what to do:

Code: Select all

for x in $(wmctrl -l|tr " " 0:);do if [ ${x:11:2} -gt -1 ];then sleep 2s;wmctrl -ia ${x:0:10};fi;done
Also man wmctrl

Good luck :wink:
Distro-Don

Re: Simple Bash Script

Post by Distro-Don »

Did you make it executable?
gary.zw

Re: Simple Bash Script

Post by gary.zw »

Distro-Don wrote:Did you make it executable?
Yes I did. When I click on it it runs asks for the password then goes on to the repostitory and closes without doing apt-get update
User avatar
Pilosopong Tasyo
Level 6
Level 6
Posts: 1432
Joined: Mon Jun 22, 2009 3:26 am
Location: Philippines

Re: Simple Bash Script

Post by Pilosopong Tasyo »

I noticed you posted this at the Ubuntu Forums as well. I would have replied there, but seeing there were already other suggestions or approaches from others...

Anyway, if I understood your question correctly, you wanted to see it in action by showing you the actual messages that gets displayed inside a terminal window when you run it directly from the desktop. If this is the case, there's an existing thread that exactly addresses this. The general idea is if the script is run from an already-open terminal window, it will just execute the commands one after the other. If the script is run directly from a GUI, it will open a terminal window first and then run the commands.

You'll find the discussion here. The TL;DR version is here. Don't include the xfce4-terminal line. Just add the 3 sudo lines after # YOUR CODE GOES HERE # bit.

HTH. Post back if it addresses your issue.
o Give a man a fish and he will eat for a day. Teach him how to fish and he will eat for a lifetime!
o If an issue has been fixed, please edit your first post and add the word [SOLVED].
gary.zw

Re: Simple Bash Script

Post by gary.zw »

Thank you Pilosopong Tasyo ! That worked perfect. The only thing though is the script file name has to be one word. If you have two words in the file name it won't work but that is not really a problem.
User avatar
jimallyn
Level 19
Level 19
Posts: 9075
Joined: Thu Jun 05, 2014 7:34 pm
Location: Wenatchee, WA USA

Re: Simple Bash Script

Post by jimallyn »

Gary, you can probably have multiple words in the name, if you don't use spaces between them. Use CamelCase, or separate_with_underscores.
“If the government were coming for your TVs and cars, then you'd be upset. But, as it is, they're only coming for your sons.” - Daniel Berrigan
gary.zw

Re: Simple Bash Script

Post by gary.zw »

jimallyn wrote:Gary, you can probably have multiple words in the name, if you don't use spaces between them. Use CamelCase, or separate_with_underscores.
Good idea jimallyn. Thank you.
User avatar
Pilosopong Tasyo
Level 6
Level 6
Posts: 1432
Joined: Mon Jun 22, 2009 3:26 am
Location: Philippines

Re: Simple Bash Script

Post by Pilosopong Tasyo »

You're welcome. :D
o Give a man a fish and he will eat for a day. Teach him how to fish and he will eat for a lifetime!
o If an issue has been fixed, please edit your first post and add the word [SOLVED].
Locked

Return to “Beginner Questions”