Special Shell Variables

June 06, 2005
These are the special shell variables which can be used in shell scripts in Linux.

$# - Denotes the number of arguments you have passed to the shell script from the command line.

$@ - All arguments, as separate words.

$* - All arguments, as one word.

$$ - ID of the current process.

$? - Exit status of the last command.

$0,$1,..$9,${10},${11}…${N} - These are positional parameters. After “9″ you must use the ${k} syntax.

Here is an example of a shell script using one of the special shell variables.

#!/bin/sh
#File: test.sh

  echo $$

I have used the code echo $$. If you run the script, it will print its process ID.

To know more about a process in Linux, read the article -
What is a process in Linux ?.

0 comments: