$# : Number of arguments passed via script
$0 : Name of the script
$@ : Names of arguments passed to the script at execution
$$ : Process ID associated with script
$OSTYPE : What’s the OS type?
$TERM :Â What’s term is being used?
$USER : What’s the username that executed the script?
$HOSTNAME : What’s the hostname of the box that ran the script?
$LOGNAME :Â What was the login username?
$LINENO : Current line # of the script
$RANDOM : Random #
$BASH_SOURCE :Â What’s the bash source?
Example script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#! /bin/bash echo "Number of arguments passed via script: " $# echo "Name of the Script: " $0 echo "Names of arguments passed via the script: " $@ echo "Whats the process ID associated with this script: " $$ echo "What was the username that started this script: " $USER echo "What was the hostname of the box that ran this script: " $HOSTNAME echo "The number of seconds since the script was started: " $SECONDS echo "Random number, please: " $RANDOM echo "Whats the current line # on this script: " $LINENO echo "What is my bash source? " $BASH_SOURCE echo "Whats the login name? " $LOGNAME echo "Whats my term? " $TERM echo "Whats the OS type? " $OSTYPE |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
$ bash test.bash.args.sh this is a goofy ass test Number of arguments passed via script: 6 Name of the Script: test.bash.args.sh Names of arguments passed via the script: this is a goofy ass test Whats the process ID associated with this script: 15420 What was the username that started this script: testuser What was the hostname of the box that ran this script: evergreen.corp The number of seconds since the script was started: 0 Random number, please: 27597 Whats the current line # on this script: 11 What is my bash source? test.bash.args.sh Whats the login name? testuser Whats my term? xterm-256color Whats the OS type? linux-gnu |