O'Reilly logo

Ubuntu Unleashed 2013 Edition: Covering 12.10 and 13.04, Eighth Edition by Matthew Helmke

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Built-In Variables

Built-in variables are special variables provided to shell by Linux that you can use to make decisions within a shell program. You cannot modify the values of these variables within the shell program.

Some of these variables are:

$#—Number of positional parameters passed to the shell program

$?—Completion code of the last command or shell program executed within the shell program (returned value)

$0—The name of the shell program

$*—A single string of all arguments passed at the time of invocation of the shell program

To show these built-in variables in use, here is a sample program called mypgm2:

#!/bin/sh#my test programecho "Number of parameters is $#"echo "Program name is $0"echo "Parameters as a single string is ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required