Page 1 of 1

Simple Bash Script

Posted: Sun Aug 24, 2014 4:41 pm
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

Re: Simple Bash Script

Posted: Sun Aug 24, 2014 5:10 pm
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:

Re: Simple Bash Script

Posted: Sun Aug 24, 2014 10:03 pm
by Distro-Don
Did you make it executable?

Re: Simple Bash Script

Posted: Sun Aug 24, 2014 10:08 pm
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

Re: Simple Bash Script

Posted: Mon Aug 25, 2014 12:17 am
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.

Re: Simple Bash Script

Posted: Mon Aug 25, 2014 1:11 am
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.

Re: Simple Bash Script

Posted: Mon Aug 25, 2014 2:12 am
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.

Re: Simple Bash Script

Posted: Mon Aug 25, 2014 2:13 am
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.

Re: Simple Bash Script

Posted: Mon Aug 25, 2014 2:42 am
by Pilosopong Tasyo
You're welcome. :D