Reply
Thread Tools
Posts: 25 | Thanked: 10 times | Joined on May 2010
#1
I have a sequence of commands that I regularly perform in xterm - is it possible to create an xterm equivalent of a Windows batch file, so I don't have to type in each individual command each time?
 
jedi's Avatar
Posts: 1,411 | Thanked: 1,330 times | Joined on Jan 2010 @ Tatooine
#2
Yes, but it's called a script. Or sometimes a shell script...
 

The Following User Says Thank You to jedi For This Useful Post:
Posts: 842 | Thanked: 1,197 times | Joined on May 2010
#3
It's called a shell-script, and they are very common in the lnux world.
The thing to remember is that a proper shell-script always has:
#!/bin/sh
as it's first line. All other lines can be regular commands.
You will need to move your file to /home/user/ (home dorectory)before it can be properly used - MyDocs doesn't play well with linux stuff.
Then, make it excecutable by typing: "chmod +x ./myshellscript.sh"
You can then run it by typing "./myshellscript.sh" from your home directory.
__________________
My projects: BackupMenu - OS Backup & restore | Video: Flashing your n900(LiveCD)
My devices: N770 + 8GB SD card soldered internally, N900 with 8GB SD card + Custom OC(125-950 typically).
OC freqs: 0:22,90 125:22,90 250:28,180 500:30,360 550:32,400 600:34,430 700:39,430 750:41,430 805:45,430 850:47,500 900:50,500 950:54,500 1000:58,500 1100:67,520 1150:71,520
 
ossipena's Avatar
Posts: 3,159 | Thanked: 2,023 times | Joined on Feb 2008 @ Finland
#4
lets try to make a tutorial out from this.

open terminal and type following:
Code:
echo "#!/bin/sh" > ./nameofyourscript.sh
echo "first command" >> ./nameofyourscript.sh
echo "second command" >> ./nameofyourscript.sh
echo "third command >> ./nameofyourscript.sh
echo "you probably get the point by now" >> ./nameofyourscript.sh
do this only once when doing the first script!
(creates a folder called scripts into ext3 partition where you can flag your script +x, aka allow execution)

Code:
mkdir /home/user/scripts/
and then every time:
Code:
mv ./nameofyourscript.sh /home/user/scripts
chmod +x /home/user/scripts/nameofyourscript.sh
ln -s /home/user/scripts/nameofyourscript.sh
now the script can be executed by opening terminal and saying:
Code:
./nameofyourscript.sh
disclaimer: there might be some errors
__________________
Want to know something?
K.I.S.S. approach:
wiki category:beginners. Browse it through and you'll be much wiser!
If the link doesn't help, just use
Google Custom Search
 

The Following 2 Users Say Thank You to ossipena For This Useful Post:
jedi's Avatar
Posts: 1,411 | Thanked: 1,330 times | Joined on Jan 2010 @ Tatooine
#5
Not trying to big, clever or funny but there's an absolute mountain of documentation, tutorials and how-to's on the net...

http://www.google.com/search?q=how+t...a+shell+script
 
pelago's Avatar
Posts: 2,121 | Thanked: 1,540 times | Joined on Mar 2008 @ Oxford, UK
#6
Originally Posted by ossipena View Post
open terminal and type following:
Code:
echo "#!/bin/sh" > ./nameofyourscript.sh
echo "first command" >> ./nameofyourscript.sh
echo "second command" >> ./nameofyourscript.sh
echo "third command >> ./nameofyourscript.sh
echo "you probably get the point by now" >> ./nameofyourscript.sh
Although that will work that's a pretty odd way to write a script. I would recommend installing leafpad then doing "leafpad nameofyourscript.sh" for this bit.
 

The Following User Says Thank You to pelago For This Useful Post:
Posts: 1,096 | Thanked: 760 times | Joined on Dec 2008
#7
Originally Posted by pelago View Post
Although that will work that's a pretty odd way to write a script. I would recommend installing leafpad then doing "leafpad nameofyourscript.sh" for this bit.
another note there vectorspace, since you are just starting making sheel scripts in linux, you should know that your choice of text editor will color you in the eyes of others forever.

If you want a free comparative analysis of text editors just post something like this

vi sux, nano rulez
 
Posts: 2,802 | Thanked: 4,491 times | Joined on Nov 2007
#8
Originally Posted by pelago View Post
Although that will work that's a pretty odd way to write a script.
http://xkcd.com/378/
 

The Following 3 Users Say Thank You to lma For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 12:39.