Script para imprimir todos los parámetros de script y verificar que tenga de uno a tres parámetros.
#!/bin/bash
if [ "$#" -lt 1 ] || [ "$#" -gt 3 ]; then
echo "An invalid number of parameters. Provide from one to three parameters"
#Most tools like ls also return 2 on invalid arguments.
exit 2
fi
printf "Number of Parameters:\t $# \n\n" ,
printf "Parametros: \t$*\n\n"
Ejemplos de ejecución:
[aurlen@monitor tmp]$ ./parametros.sh
An invalid number of parameters. Provide from one to three parameters
[aurlen@monitor tmp]$
[aurlen@monitor tmp]$
[aurlen@monitor tmp]$ ./parametros.sh 1 dos 3
Number of Parameters: 3
Parametros: 1 dos 3
[aurlen@monitor tmp]$ ./parametros.sh 1 dos 3 cuatro
An invalid number of parameters. Provide from one to three parameters
[aurlen@monitor tmp]$
[aurlen@monitor tmp]$
[aurlen@monitor tmp]$