There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Tag Cloud
access acer asus bios bsod computer crash drive driver drivers error ethernet excel freeze games gaming hard drive hardware hdmi internet java laptop malware memory monitor motherboard music network obp printer problem ram random registry router slow software sound trojan usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
How to save a shell script

Reply  
Thread Tools
new_techie's Avatar
Junior Member with 6 posts.
 
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
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.
Reply

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 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



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 07:04 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.