LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-02-2010, 03:00 AM   #1
new.2.linux
LQ Newbie
 
Registered: Oct 2009
Posts: 1

Rep: Reputation: 0
Question Learning Shell script


I am new to Linux. I want to learn shell scripting. So where to start and what are the prerequisites? Are shell scripts portable among different linux os? (Does a script written for CentOS, run on Fedora or on Ubuntu without any modification?)
 
Old 07-02-2010, 03:17 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Scripts are written for shells, not operating systems. A script written with bash syntax can run on just about any system with bash installed (which includes pretty much all linux systems). Most shells use similar syntaxes though, as they are all rooted in the same posix standards, so an individual script may or may not also run under a different shell, depending on whether it uses any shell-specific features. A script written specifically to posix specifications should be executable in almost any shell.

Of course, the target system must have all the appropriate programs the script uses installed too, and things like differences in file and directory structures can also affect portability.

In any case, there are many good tutorials out there. Just pick one and start working through it. Since a script is basically just a series of shell commands encapsulated in flow-control structures, most of what you learn can be used both inside and outside scripts.

I personally recommend linuxcommand as a good starting point. It's easy to read and leads you step-by-step through the basics. Then for more detail on individual features, go on to the bash beginners guide. Once you know what you're doing, the Advanced Bash Scripting Guide will probably become your main resource.

http://www.linuxcommand.org/index.php
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/index.html

Last edited by David the H.; 07-02-2010 at 03:26 AM. Reason: clarification
 
1 members found this post helpful.
Old 07-02-2010, 03:50 AM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
By the way, while not exactly necessary for learning scripting, a lot of scripting generally involves grabbing filenames and manipulating text. So you'll certainly find yourself using the commands find, sed, and awk a lot, which come with their own complex syntax and scripting systems. The Unix grymoire has pages dealing with all three of these commands.

http://www.grymoire.com/Unix/

(Note though that the grymoire is written for older unix-based versions of these commands, and there are some differences between them and the gnu versions that Linux uses, but it's good for getting the basics down.)

Finally, you'll also eventually want to learn regular expressions. All of the above commands, as well the shell itself, use regex in one form or another, so it's well worth learning. I don't have any specific page to suggest here, but there are tons of tutorials out there, so look around.
 
1 members found this post helpful.
Old 07-02-2010, 08:02 AM   #4
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,541
Blog Entries: 23

Rep: Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943
Hi,

There's more to scripting then learning format. I suggest that the following references will aid in the endeavor(s);

Linux Documentation Project
Rute Tutorial & Exposition
Linux Command Guide
Utimate Linux Newbie Guide
LinuxSelfHelp
Getting Started with Linux
Bash Reference Manual <<< Good references for bash
Advanced Bash-Scripting Guide <<< Good reference for bash examples
Linux Home Networking
Virtualiation- Top 10


The above links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links!
 
Old 07-02-2010, 10:40 AM   #5
myposts
Member
 
Registered: Jun 2010
Posts: 46

Rep: Reputation: 21
here...

At unixacademy.com ... you can both learn and get the certification and there's free exams on site too. I use it a lot.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Executing a Shell script with 654 permissions inside another shell script. changusee2k Linux - Newbie 2 06-07-2011 08:58 PM
Help needed learning to write a shell script for logons nistur Linux - Networking 8 10-02-2004 03:34 AM
learning how to write shell ashley75 Linux - General 3 05-07-2004 03:05 AM
learning Shell script ???? Atrocity Programming 3 02-02-2003 02:49 PM


All times are GMT -5. The time now is 11:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration