Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does ${1} and ${*} do? [duplicate]

Tags:

linux

bash

nagios

This Nagios script uses ${1} and ${*} like so

if [ "${1}" ]; then
    if [ "${ERRORSTRING}" ]; then
        echo "${ERRORSTRING} ${OKSTRING}" | sed s/"^\/ "// | mail -s "$(hostname -s): ${0} reports errors\
" -E ${*}
    fi
else
    if [ "${ERRORSTRING}" -o "${OKSTRING}" ]; then
        echo "${ERRORSTRING} ${OKSTRING}" | sed s/"^\/ "//
        exit ${ERR}
    else
        echo no zpool volumes found
        exit 3
    fi
fi

Question

What does ${1} and ${*} do?

like image 813
Sandra Schlichting Avatar asked Aug 05 '26 11:08

Sandra Schlichting


1 Answers

The command-line arguments $1, $2, $3,...$9 are positional parameters, with $0 pointing to the actual command, program, shell script, or function and $1, $2, $3, ...$9 as the arguments to the command.

"$*" special parameter takes the entire list as one argument with spaces between and the "$@" special parameter takes the entire list and separates it into separate arguments.

Suppose test.sh given below:

#!/bin/sh 
echo "File Name: $0" 
echo "First Parameter : $1" 
echo "First Parameter : $2" 
echo "Quoted Values: $@" 
echo "Quoted Values: $*" 
echo "Total Number of Parameters : $#"

enter image description here

like image 55
Tajinder Avatar answered Aug 07 '26 07:08

Tajinder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!