Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Search Search
Search for:
Tech Support Guy > > >

How to save a shell script


(!)

new_techie's Avatar
new_techie new_techie is offline
Junior Member with 6 posts.
THREAD STARTER
 
Join Date: Nov 2007
20-Nov-2007, 07:52 AM #1
How to save a shell script
Hey,

So I'm new to programming in Linux/Unix. Can anyone tell me how I can write a shell script and then save it? As in write a little programme and then be able to execute it whenever I like? I'm stating the obvious by saying I don't have to type the whole thing each time. Does anyone know a good website for learning how to write scripts?

Thanks all!
RobLinux's Avatar
RobLinux RobLinux is offline
Computer Specs
Member with 417 posts.
 
Join Date: Nov 2007
Location: UK
Experience: UNIX/Linux Pro, M$ 'doze Sufferer
20-Nov-2007, 08:50 AM #2
Quote:
Originally Posted by new_techie
So I'm new to programming in Linux/Unix. Can anyone tell me how I can write a shell script and then save it? As in write a little programme and then be able to execute it whenever I like? I'm stating the obvious by saying I don't have to type the whole thing each time. Does anyone know a good website for learning how to write scripts?
$ cat > ~/bin/myscript
#!/bin/sh

# My first script
echo Foo bah!
<CNTRL-D>
$ chmod +x !$

To edit in terminal there's usually a simple editor like nano installed, or you can use GUI text editor (avoid word processor as they do dumb things to programs). If you're a touch typist, then vi(1) is the best so long as you don't mind modes and putting in a little effort to learn it, emacs(1) and most other editors like <CNTRL> and <ALT> codes for commands.

Just go to http://tldp.org/ there's Guides, read "Intro to Linux", "Bash Guid for Beginners", "Command Line Tools" and only then "Advanced Bash-Scripting".

Ubuntu's using dash, rather than bash during boot up for greater speed, so actually writing standard Bourne shell and avoiding Bash specific extensions might be an idea. dash is the BSD 4.4 shell, and like much BSD 4.4 stuff had excellent re-implementations of trad UNIX stuff. It's usually not too hard to write stuff portably, or convert from Bash-ism to a standard Bourne script.
Email This Email  Print This Print  Bookmark This Bookmark  Tweet This Send to Facebook Send to MySpace Send to StumbleUpon Digg This | More Services More
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
WELCOME TO TECH SUPPORT GUY!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.


(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑