Basic Linux Shell Scripting Concepts


By Corey Hynes, September 5th, 2002 Posted in Linux. Subscribe to our RSS Feed



Rather Have Fast and Secure Remote Control?

 Securely access PCs and servers worldwide through any firewall. Try it and see for yourself!

Input Parameters

Shell scripts can also accept input parameters. This allows you to build a multi-function script that can perform different actions each time it is executed. Input parameters are easy to use. They are automatically store in variables that represent their ordinal position when specified. For example, the first input parameter can be referenced as $1, the second as $2 and so on. Consider the following example.

#!/bin/bash
echo You told me to say $1

Save this script as [talk] and then run the following

[./talk Hello]

Looping

Looping allows the repeated execution of a section of code. This can be used to parse though repeated values, or to add multiple entries to a file. The following is the syntax of a loop.

while test; do
repeated code
loop

The keyword [break] can be used anywhere in the code to exit the loop at any point. This is typically found inside a nested if. Next is an example of a loop that counts to 10, printing the output each time.

#!/bin/bash
ctr=1
while ctr <=10; do
echo value is $ctr
$ctr=$ctr+1
loop

Written by Corey Hynes - Visit Website

Go To Page: 1 2 3 4 5



Print This Post Print This Post













All Tutorials by Category:















Entire site Copyright © 1999-2007 2000Trainers.com, all rights reserved.
Content on this site may not be copied or reproduced in any way without permission.





IT Showcase


Text Link Ads

View all Tutorials by Category: