Scripts

Soldato
Joined
5 Jul 2003
Posts
16,206
Location
Atlanta, USA
Hi.
Is there a way i can make the linux equilivent of MS DOS batch files?
Theres about 6 or so terminal commands that i would like to have in executable form.

How would i go about doing this?

Thanks in advance all. :)
 
Sure there is. It's called bash scripting. Bssentially, you write the script, save it, then run chmod +x to make it executable. someone more knowledgeable can tell you all about how to write scripts.
 
Just run vi (or your favourite editor) and make a file like this:

#!/bin/bash
<your commands here>

Then save it and do chmod +x <filename>, then just ./<filename> to run it.
 
I cant find nout.
The only thing i can find, which is to add:
Code:
#!/bin/bash
To the beginning of my code

Im saving the following:
Code:
#!/bin/bash
aticonfig --list-powerstates
To a file called 'ATI_PowerStates_Information.sh'
I then run the following in terminal:
Code:
chmod +x ATI_PowerStates_Information.sh
And nothing happens in the terminal. So i goto the file itself, double click, and all it does it open a new terminal window?

Ideas?
 
Beepcake said:
Just run vi (or your favourite editor) and make a file like this:

#!/bin/bash
<your commands here>

Then save it and do chmod +x <filename>, then just ./<filename> to run it.
Which is pretty much what i managed to find, but it doesnt work.
I want it so that they are executable from icons. :)
 
Do you want it to open a terminal and then run that command and list the output in the terminal?

If that is the case, most terminal programs (well urxvt and Eterm at least) have an "-e" switch, to open a terminal and execute a command.

eg:

urxvt -e aticonfig --list-powerstates

You could then just make a shortcut or whatever to run that.
 
riven said:
Do you want it to open a terminal and then run that command and list the output in the terminal?
It doesnt 'list' anything at all though.

Your urxvt command doesnt do nout either. :(

The way i understand to do it, is to put my previously listed code into a txt editor, save as whatever.sh, then run that chmod command, which'll make it executable, but it doesnt work!?
 
Are you in th right folder when exec script
Ie if you saved your script in /home/username/myscripts
and you open a terminal from your desktop if you run pwd you will see
you are in /home/username/ if you exec your script from there it will not run
As it's not in your path
either nav to path then exec script or
make your own bin folder in /home/username/
edit your .bash_profile in /home/username
so it looks something like this
PATH=$PATH:$HOME/bin
then save any scripts in you own bin folder and you will be able to exec them from any dir.
If this is not your prob at least you no where to save your scripts now :D
 
How about .....

To check that it actually runs correctly, open a terminal, navigate to the directory you saved the file and run the shell script, ie :

./shellscript.sh

does it give you the desired output ? If so then the script works ok.

Secondly, I believe when creating 'links to applications' in KDE (Right Click > New > Link To Application), there is usually a tick box to say 'run in terminal window' which will launch a terminal window when the icon is clicked then run the command in it and show you the output...

I've used this many times succesfully.
 
Ok then.
Hows about everything you two have suggested in what i like to call, English. ;)
Im not vastly experianced with Ubuntu as ive just started using it, so can you two list EVERY command that i have to put in, rarther than just loose descriptions of what i need to do.
Thanks. FYI, the username on the system is 'boomam'.

Thanks.
 
Ok then not sure what the program you want to use does when you run it but first you need to make sure it works.
Is a program that runs in a terminal or does it open Gui ?
 
Alright, we'll use the terminal and cd command then describe where the file is. In this example the script is called scripty.sh and it is located in /home/boomam/scripts.
Open up the terminal and type
Code:
cd /home/boomam/scripts/
Then we're going to make the script executable. Type
Code:
chmod +x scripty.sh
Now you can execute the script with
Code:
./scripty.sh

Does that work? Does the script execute in the terminal window?
 
BillytheImpaler said:
Alright, we'll use the terminal and cd command then describe where the file is. In this example the script is called scripty.sh and it is located in /home/boomam/scripts.
Open up the terminal and type
Code:
cd /home/boomam/scripts/
Then we're going to make the script executable. Type
Code:
chmod +x scripty.sh
Now you can execute the script with
Code:
./scripty.sh

Does that work? Does the script execute in the terminal window?
Yes, that works.

How do i get it so that i can have an icon somewhere, like a folder on my desktop, so i can just double click to get that command to display and run?
 
well if your using KDE you can open control center desktop panels then menus tab
click file add
then choose name for your app
the the right hand menu will be available for you to add what info and icon you require :D
 
Back
Top Bottom