Mourning the loss of our friend, WhitPhil.
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
 
Linux and Unix
Tag Cloud
access audio blue screen boot bsod connection crash dell desktop driver dvd email error excel excel 2003 firefox hard drive hardware hdmi hijackthis internet keyboard laptop malware monitor motherboard network networking outlook problem ram recovery router screen slow sound spyware tdlwsp.dll trojan upgrade vba video virus vista vundo windows windows 7 windows vista windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
How to save a shell script

Tip: Click here to scan for System Errors and Optimize PC performance
[ Sponsored Link ]

Closed Thread
 
Thread Tools
new_techie's Avatar
Junior Member with 6 posts.
 
Join Date: Nov 2007
20-Nov-2007, 06: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
Computer Specs
Senior Member with 417 posts.
 
Join Date: Nov 2007
Location: UK
Experience: UNIX/Linux Pro, M$ 'doze Sufferer
20-Nov-2007, 07: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.
Closed Thread Bookmark and Share

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.

Smart Search

Find your solution!



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.

Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 02:17 AM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.
Powered by Cermak Technologies, Inc.