Friday, November 22, 2013

Positional Parameter

In previous post, we already learn how to use variable in bash scripting.
In this article, i will share the use in shell scripting.

Positional Parameter

Positional parameter is a variabel that being used by shell to contain argumen that given to shell.
below is the example for the script:

#!/bin/bash
#argumen1

echo $1 is one of popular $2 populer in $3

if we input word beside the script
example

[elvin@Testbed$]./argumen1 bash shell linux
bash is one of popular shell in linux

In this example, we can take conclution that
word bash will be save in positional 1 ($1)
word shell will be save in positional 2 ($2)
word linux will be save in positional 3 ($3)

Below is other example for positional parameter

#!/bin/bash
#argumen2

clear
echo "Your name script   : $0";
echo "How many Argumen   : $#";
echo "The Argumen is     : $*";

and the result

[elvin@Testbed$]./argumen 1 2 3 empat
Your name script  : ./argumen
How many Argumen  : 4
The Argumen is    : 1 2 3 empat




0 comments:

Post a Comment