LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-09-2009, 09:52 AM   #1
juglers
LQ Newbie
 
Registered: Mar 2009
Posts: 7

Rep: Reputation: 0
Question i want to learn shell scripting


i want to learn shell scripting...so what are prerequisites for shell scripting...where should i begin from..suggest good reading..
in what language it is done...i heard it cannot be done in C- is that true
 
Old 04-09-2009, 09:55 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
http://www.tldp.org/LDP/Bash-Beginne...tml/index.html
http://rute.2038bug.com/node10.html.gz
http://www.tldp.org/LDP/abs/html/index.html

The shell has its own language. The shell source code is in C, but you have nothing to do with C while programming in shell, except for some similar syntax.
 
Old 04-09-2009, 12:56 PM   #3
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by juglers View Post
i want to learn shell scripting...so what are prerequisites for shell scripting...where should i begin from..suggest good reading..
in what language it is done...i heard it cannot be done in C- is that true
Is there a real need for you to know shell scripting ?

Shell scripts are considered to be difficult to maintain, and shell language is limited compared to more moder advanced scripting languages.

Even though I work with UNIX-like systems since 1991, I haven't found a compelling reason to learn shell deeply, though I know the basics and simple everyday things, but nothing fancy.

My language of choice is Perl, after it "C".
 
Old 04-09-2009, 02:34 PM   #4
Robhogg
Member
 
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 97
Some things are easier in the shell (interacting with files, the filesystem and system processes), while others are easier in Perl (working with databases, anything that needs more than integer arithmetic and rudimentary data structures). I use both, though I came first to shell scripting.

I started off mainly by Googling for stuff as I needed it, but there is good material out there. Try The Rute User's Guide (a bit old, but still good) or the Linux Documentation Project's Advanced Bash Scripting Guide (it does start at the beginning, honest!) for starters.

Then learn Perl.
 
Old 04-09-2009, 02:49 PM   #5
khodeir
Member
 
Registered: Feb 2009
Distribution: Debian
Posts: 243

Rep: Reputation: 33
if you want my idea
try Tcl
it can make GUI and same functionality of shell scripting and more easier\
at the end it is back to u
 
Old 04-09-2009, 04:30 PM   #6
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by khodeir View Post
if you want my idea
try Tcl
it can make GUI and same functionality of shell scripting and more easier\
at the end it is back to u
Neither TCL, nor shell are compilable, so you catch your errors only after
interpreter arrives to them during execution, if at all. I.e. a corner case may be caught years after creation.

Perl/Python/Ruby and the like are first compiled into at least parse tree.
 
Old 04-09-2009, 06:54 PM   #7
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
As said many times, use the tools best suited for the purpose. If it comes to starting and stopping other processes, file handling etc. use shell scripting.

If shell scripting is so bad, why almost all of the init.d files are written in shell script?

I don't know Perl, so that precludes any preference for Perl. But I do know TCL quite well, and there are a lot of situations where I prefer shell over TCL for various reasons. And the other way around.

jlinkels
 
Old 04-10-2009, 05:04 AM   #8
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
There are also good tutorials here:
http://www.grymoire.com/Unix/
 
Old 04-10-2009, 01:59 PM   #9
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by jlinkels View Post
As said many times, use the tools best suited for the purpose. If it comes to starting and stopping other processes, file handling etc. use shell scripting.

If shell scripting is so bad, why almost all of the init.d files are written in shell script?

I don't know Perl, so that precludes any preference for Perl. But I do know TCL quite well, and there are a lot of situations where I prefer shell over TCL for various reasons. And the other way around.

jlinkels
"Bad" is a relative term. Shell interpreter occupies less memory than Perl one, for example.

But nowadays memory consumption is less of a concern, and with the existence of persistent Perl startup times can be minimized. And with caching it's small anyway.

In the end, it's a matter of habit. If I am ever to have a need to deal with startup scripts seriously, I'll do this in Perl.

FWIW, there are even Perl interactive shells around.
 
Old 04-10-2009, 02:22 PM   #10
Robhogg
Member
 
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 97
Quote:
Originally Posted by Sergei Steshenko View Post
"Bad" is a relative term...
Yes, that it is.

Certain tasks are easier in certain languages than they are in others. You can perform almost any systems admin task in Perl, just as you could use a chef's knife to chop vegetables, dig a hole or perform an emergency tracheostomy. Doesn't mean that it would be as neat and easy for each. Trowels and scalpels have their place. So does shell scripting.


Last edited by Robhogg; 04-10-2009 at 02:33 PM.
 
Old 04-11-2009, 05:33 PM   #11
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
each shell is a language.
like DOS is a language (.bat files)

csh
sh
bash
ksh

are all languages.
don't bother with csh, learn bash.
bash, sh and ksh are all similar.

all unix systems' init scripts are shell scripts, so it is important to learn.
 
Old 04-12-2009, 03:35 AM   #12
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Quote:
Originally Posted by bigearsbilly View Post
each shell is a language.
like DOS is a language (.bat files)

csh
sh
bash
ksh

are all languages.
don't bother with csh, learn bash.
bash, sh and ksh are all similar.

all unix systems' init scripts are shell scripts, so it is important to learn.
I think the terms Bourne-shell compatible and Bourn-again-shell compatible are more correct than saying they are similar. ksh may be an enhanced bash, but it is still Bourn-again-shell compatible, and that's what's important. If you write a bash-compatible script it will work on both ksh and bash and others. If you write an sh-compatible script it should work on bash and ksh too. But bash may not work using sh, but then no one uses sh anymore AFAIK.
 
Old 04-12-2009, 05:34 AM   #13
quantt
Member
 
Registered: Aug 2008
Posts: 62

Rep: Reputation: 15
hello,
However, perl arrays works too slow than awk. Shells scripting may to begin learn from run scripts /etc/init.d, but what's you goal? Just do what your needs.
 
  


Reply



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
Which scripting language to learn max_cherry Linux - Newbie 11 11-27-2008 12:47 PM
Book to Learn Shell Scripting pramka Linux - Newbie 2 04-22-2008 02:55 AM
how to learn shell scripting G.Verma Linux - Laptop and Netbook 2 10-17-2007 06:55 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 04:29 AM
Want to learn Shell Scripting dawood Linux - General 3 08-04-2004 06:59 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:49 AM.

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
Open Source Consulting | Domain Registration