RSS Subscription
Linux Howtos & Tutorials

Enter your email:

Delivered by


NOTE:New tutorials are from LinuxCareer.com

Poll

Do you own or wish to have iPhone?
 


Linux eBooks FREE Download
A guide to programming Linux kernel modules
Introduction to Linux - A Hands on Guide
A Newbie's Getting Started Guide to Linux

Linux from Scratch - Create Your Own Linux System - Free eBook

Linux: The Hacking Solution (v.3.0)

SQLite 3 with PHP Essential Training – Free Video Training Tutorials

This guide will introduce you to the world of GNU/Linux

The GNU/Linux Advanced Administration

A Complete Beginner's Manual for Ubuntu 10.04 (Lucid Lynx)

Advanced Bash-Scripting Guide

Set up, maintain, and secure a small office email server

Partner Linux Sites:
How-To.LinuxCareer.com
Jobs.LinuxCareer.com
TuxMachines
Monsterb
LinuxBloggers
AdamsInfo
LinuxScrew
All For Linux

The difference between parameter and variable in bash

Article Index
1. Variable
2. Positional parameter
3. Special Parameters

Question:

Hi, in bash context what is the difference between parameter and variable?

Answer:

In a bash context a parameter is an entity that stores values. Furthermore, a parameter can be a name ( variable ), number ( positional parameter ) or special character ( special parameter ). Therefore, a variable is a parameter denoted by a name. ( see: man bash ). Let's have a closer look on all three bash parameters:

1. Variable

Variable has a value assigned to it. It also can have 0 or more attributes. A value may be assigned to a variable by a following statement:

name=[value]

Example:

#!/bin/bash

myname="Gnu Bash"
printf "%s\n" "$myname"

2. Positional parameter

Positional parameter is denoted by one or digits. It is assigned by one or more arguments supplied to a script upon the script execution.
Example:

 #!/bin/bash

printf "%s\n" "My name is $1 $2"

3. Special Parameters

Special parameters are denoted by a one or more special characters from a following list: *, @, #, ?, -, $, !, 0 and _ . For example * expands to positional parameters. In other words it prints all arguments supplied on the command line upon the script execution:

 #!/bin/bash
echo $*

OUTPUT:

./special GNU Bash parameter vs variable
GNU Bash parameter vs variable

Linux questions and answers

Share this linux post:

Submit The difference between parameter and variable in bash in Delicious Submit The difference between parameter and variable in bash in Digg Submit The difference between parameter and variable in bash in FaceBook Submit The difference between parameter and variable in bash in Google Bookmarks Submit The difference between parameter and variable in bash in Stumbleupon Submit The difference between parameter and variable in bash in Technorati Submit The difference between parameter and variable in bash in Twitter
 
Comments for this page are closed !!!
Please visit our new Linux Forum for additional help or discussion.


Linux eBooks FREE Download