Skip to Content
Learning Linux Shell Scripting - Second Edition
book

Learning Linux Shell Scripting - Second Edition

by Ganesh Sanjiv Naik
May 2018
Beginner
332 pages
7h 28m
English
Packt Publishing
Content preview from Learning Linux Shell Scripting - Second Edition

Understanding set

Many times, we may not pass arguments to the command line, but we may need to set parameters internally inside the script.

We can declare parameters with the set command, as follows:

$ set USA Canada UK France$ echo $1USA$ echo $2Canada$ echo $3UK$ echo $4France

We can use this inside the set_01.sh script, as follows:

#!/bin/bash 
set USA Canada UK France 
echo $1 
echo $2 
echo $3 
echo $4 

Run the script as this:

$ ./set.sh

The output is as follows:

USACanadaUKFrance

Following is a summary of the declare options:

Option

Meaning

-a

An array is created

-f

Displays the function names and definitions

-F

Displays only the function names

-i

Makes the variables integer types

-r

Makes the variables ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Linux Shell Scripting

Learning Linux Shell Scripting

Ganesh Sanjiv Naik
Linux Shell Scripting Cookbook - Third Edition

Linux Shell Scripting Cookbook - Third Edition

Clif Flynt, Sarath Lakshman, Shantanu Tushar

Publisher Resources

ISBN: 9781788993197Supplemental Content