sai
sai

Reputation: 5167

What is shell scripting?

What exactly is shell scripting?

And what is Bash, Korn, and Expect? I use a few commands in a Linux terminal, is that shell scripting too? Again I am confused what exactly is shell scripting?

Upvotes: 4

Views: 3176

Answers (5)

atul
atul

Reputation: 61

A shell allows you create one or more pipelines of processes.

One hallmark of the pipes and filters theme - is combining together the tools - the tools are filters - e.g. ls, egrep, paste, bc, wc... You can create your own filters/tools too - and combine them.

The shell defines the syntax for combining filters using pipes. It also gives you a way to test for condition, via the if keyword - and write loops. You can write functions too.

In short, you can write programs - using tools which are mostly there - and create very powerful, tailor made functionality to suite your needs - very quickly. This is scripting - combine and reuse existing tools as scripts in fruitful ways

For example, consider the pipeline
% seq 100 | paste -s -d '*'
1*2*3*4*5*6*7*8*9*10...98*99*100

The person who wrote the seq filter would not have imagined seq used like above. The seq program, by itself, is simple. This ability to arbitrarily connect seq with paste (or some other filter tool) - makes it an extremely powerful concept.

For example, consider the pipeline
% seq 100 | paste -s -d '*' | bc
93326215443944152681699...
It takes the expression (as above) - and feeds it to bc - yet another filter - bc evaluates the multiplication expression.

In short, a shell script allows you to combine/reuse existing tools - with the flow control mechanisms like if, while... to create very powerful programs in a pretty short time.

Upvotes: 0

In addition to being an interaction environment the shell (be it the original Bourne shell (/bin/sh) or one of the many alternatives (ksh, csh, bash, zsh, tcsh, ...) with different or extended syntax) provides programming language like features (looping, conditionals, functions, variables...).

Shell scripting is more or less writing a program in you favorite shell.

The line between using the shell and scripting is fuzzy, but I'd put it near "solving a class of problems by writing some shell code that is smart in some way".

Upvotes: 3

karlw
karlw

Reputation: 668

http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=define:+shell+script

Shell scripting lets you automate tasks that you do from the command line.

Upvotes: 4

nos
nos

Reputation: 229058

Your terminal runs a shell , probably bash - korn, csh and others are similar shells with different features and syntax.

While you probably use it mostly to run commands, most shells are an interpreter for command language defined by that shell. Programs in that language is called a shell script. See this howto for an overview of shell scripting in bash.

Upvotes: 10

Wayne Werner
Wayne Werner

Reputation: 51797

Shell scripting is the process of creating a file containing several shell commands (i.e. ls, cd, grep, etc) than can then be executed.

bash and korn are both shells - they allow you to interface with the computer through a command line, rather than running programs by clicking on icons.

The purpose of shell scripting is to automate repetitive tasks, such as setting up an environment to launch a program, or checking to see if logfiles have changed, or archiving a directory (or set of directories) or any other number of tasks.

Check this out for more info.

Upvotes: 6

Related Questions