Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7415477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:18:39+00:00 2026-05-29T07:18:39+00:00

In BASH, is it possible to get the function name in function body? Taking

  • 0

In BASH, is it possible to get the function name in function body? Taking following codes as example, I want to print the function name “Test” in its body, but “$0” seems to refer to the script name instead of the function name. So how to get the function name?

#!/bin/bash

function Test
{
    if [ $# -lt 1 ]
    then
        #   how to get the function name here?
        echo "$0 num" 1>&2
        exit 1
    fi
    local num="${1}"
    echo "${num}"
}

#   the correct function
Test 100

#   missing argument, the function should exit with error
Test

exit 0
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:18:40+00:00Added an answer on May 29, 2026 at 7:18 am

    Try ${FUNCNAME[0]}. This array contains the current call stack. To quote the man page:

       FUNCNAME
              An  array  variable  containing the names of all shell functions
              currently in the execution call stack.  The element with index 0
              is the name of any currently-executing shell function.  The bot‐
              tom-most element is "main".  This variable exists  only  when  a
              shell  function  is  executing.  Assignments to FUNCNAME have no
              effect and return an error status.  If  FUNCNAME  is  unset,  it
              loses its special properties, even if it is subsequently reset.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to get the list of running Apps using Bash? I'm not
I have installing msysgit. When launching Git bash I get the following error, which
Writing a bash script, and I want to get user input. Awesome, read -p
Is it possible to get, using Bash, a list of commands starting with a
In bash echo ${!X*} will print all the names of the variables whose name
Is it possible to check a bash script syntax without executing it? Using Perl,
In bash, I believe it is possible to enable tab completion on the terminal
is it possible to assign variable inside if conditional in bash 4? ie. in
I have heard that it is possible to get a bitmap/image handle of the
Is it possible via the command line to get the current open tab url

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.