Simple Bash Script

All Gurus once were Newbies
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. Please stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions prefer the other forums within the support section.
Before you post please read this

Simple Bash Script

Postby gary.zw on Sun Aug 24, 2014 4:41 pm

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
gary.zw
Level 1
Level 1
 
Posts: 22
Joined: Thu Sep 13, 2012 4:10 pm

Linux Mint is funded by ads and donations.
 

Re: Simple Bash Script

Postby WharfRat on Sun Aug 24, 2014 5:10 pm

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:
Image
User avatar
WharfRat
Level 12
Level 12
 
Posts: 4271
Joined: Thu Apr 07, 2011 8:15 pm

Re: Simple Bash Script

Postby Distro-Don on Sun Aug 24, 2014 10:03 pm

Did you make it executable?
Distro-Don
Level 2
Level 2
 
Posts: 90
Joined: Thu May 23, 2013 8:43 pm

Re: Simple Bash Script

Postby gary.zw on Sun Aug 24, 2014 10:08 pm

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
gary.zw
Level 1
Level 1
 
Posts: 22
Joined: Thu Sep 13, 2012 4:10 pm

Re: Simple Bash Script

Postby Pilosopong Tasyo on Mon Aug 25, 2014 12:17 am

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.
Image
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].
User avatar
Pilosopong Tasyo
Level 6
Level 6
 
Posts: 1176
Joined: Mon Jun 22, 2009 3:26 am
Location: Philippines

Re: Simple Bash Script

Postby gary.zw on Mon Aug 25, 2014 1:11 am

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.
gary.zw
Level 1
Level 1
 
Posts: 22
Joined: Thu Sep 13, 2012 4:10 pm

Re: Simple Bash Script

Postby jimallyn on Mon Aug 25, 2014 2:12 am

Gary, you can probably have multiple words in the name, if you don't use spaces between them. Use CamelCase, or separate_with_underscores.
jimallyn
Level 4
Level 4
 
Posts: 331
Joined: Thu Jun 05, 2014 7:34 pm
Location: Wenatchee, WA USA

Re: Simple Bash Script

Postby gary.zw on Mon Aug 25, 2014 2:13 am

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.
gary.zw
Level 1
Level 1
 
Posts: 22
Joined: Thu Sep 13, 2012 4:10 pm

Re: Simple Bash Script

Postby Pilosopong Tasyo on Mon Aug 25, 2014 2:42 am

You're welcome. :D
Image
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].
User avatar
Pilosopong Tasyo
Level 6
Level 6
 
Posts: 1176
Joined: Mon Jun 22, 2009 3:26 am
Location: Philippines

Linux Mint is funded by ads and donations.
 

Return to Newbie Questions

Who is online

Users browsing this forum: No registered users and 17 guests