Skip to main content
Tweeted twitter.com/StackUnix/status/1111644359991152641
Became Hot Network Question
added 1 character in body
Source Link
GAD3R
  • 69.9k
  • 32
  • 147
  • 216

I have written a little function that exits if the value of the function argument is empty, I would like to be able to also print the name of the parameter  (not the value!) if it is possible, my following implementation fails to print the name of the parameter.

function exitIfEmpty()
{
        if [ -z "$1" ]
        then
        echo "Exiting because ${!1} is empty"
        exit 1
        fi
}

when called like so

exitIfEmpty someKey

should print

Exiting because someKey is empty

I have written a little function that exits if the value of the function argument is empty, I would like to be able to also print the name of the parameter(not the value!) if it is possible, my following implementation fails to print the name of the parameter.

function exitIfEmpty()
{
        if [ -z "$1" ]
        then
        echo "Exiting because ${!1} is empty"
        exit 1
        fi
}

when called like so

exitIfEmpty someKey

should print

Exiting because someKey is empty

I have written a little function that exits if the value of the function argument is empty, I would like to be able to also print the name of the parameter  (not the value!) if it is possible, my following implementation fails to print the name of the parameter.

function exitIfEmpty()
{
        if [ -z "$1" ]
        then
        echo "Exiting because ${!1} is empty"
        exit 1
        fi
}

when called like so

exitIfEmpty someKey

should print

Exiting because someKey is empty
added 16 characters in body
Source Link
xerxes
  • 359
  • 2
  • 8

I have written a little function that exits if the value of the function argument is empty, I would like to be able to also print the name of the parameter(not the value!) if it is possible, my following implementation fails to print the name of the parameter.

function exitIfEmpty()
{
        if [ -z "$1" ]
        then
        echo "Exiting because ${!1} is empty"
        exit 1
        fi
}

when called like so

exitIfEmpty someKey

should print

Exiting because someKey is empty

I have written a little function that exits if the value of the function argument is empty, I would like to be able to also print the name of the parameter if it is possible, my following implementation fails to print the name of the parameter.

function exitIfEmpty()
{
        if [ -z "$1" ]
        then
        echo "Exiting because ${!1} is empty"
        exit 1
        fi
}

when called like so

exitIfEmpty someKey

should print

Exiting because someKey is empty

I have written a little function that exits if the value of the function argument is empty, I would like to be able to also print the name of the parameter(not the value!) if it is possible, my following implementation fails to print the name of the parameter.

function exitIfEmpty()
{
        if [ -z "$1" ]
        then
        echo "Exiting because ${!1} is empty"
        exit 1
        fi
}

when called like so

exitIfEmpty someKey

should print

Exiting because someKey is empty
Source Link
xerxes
  • 359
  • 2
  • 8

Print name if parameter passed to function

I have written a little function that exits if the value of the function argument is empty, I would like to be able to also print the name of the parameter if it is possible, my following implementation fails to print the name of the parameter.

function exitIfEmpty()
{
        if [ -z "$1" ]
        then
        echo "Exiting because ${!1} is empty"
        exit 1
        fi
}

when called like so

exitIfEmpty someKey

should print

Exiting because someKey is empty