Answers for "create bash function with arguments"

1

How to Pass Arguments to a Bash Script

makereport -u jsmith -p notebooks -d 10-20-2011 -f pdf

#!/bin/bash
while getopts u:d:p:f: option
do
case "${option}"
in
u) USER=${OPTARG};;
d) DATE=${OPTARG};;
p) PRODUCT=${OPTARG};;
f) FORMAT=${OPTARG};;
esac
done
Posted by: Guest on October-30-2021
0

bash function arguments

Function shell variables
All function parameters or arguments can be accessed via $1, $2, $3,..., $N.
$0 always point to the shell script name.
$* or $@ holds all parameters or arguments passed to the function.
$# holds the number of positional parameters passed to the function.
How do I display function name?
$0 always point to the shell script name. However, you can use an array variable called FUNCNAME which contains the names of all shell functions currently in the execution call stack. The element with index 0 is the name any currently-executing shell function.This variable exists only when a shell function is executing.

FUNCNAME in action
Create a shell script called funcback.sh:




#!/bin/bash
#  funcback.sh : Use $FUNCNAME
backup(){
	local d="$1"
	[[ -z $d ]] && { echo "${FUNCNAME}(): directory name not specified"; exit 1; }
	echo "Starting backup..."
}

backup $1
Posted by: Guest on March-06-2022

Code answers related to "create bash function with arguments"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language