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 8652043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:12:57+00:00 2026-06-12T14:12:57+00:00

I have the following code in my ~/.bashrc: date=$(which date) date() { if [[

  • 0

I have the following code in my ~/.bashrc:

date=$(which date)
date() {
  if [[ $1 == -R || $1 == --rfc-822 ]]; then
    # Output RFC-822 compliant date string.
    # e.g. Wed, 16 Dec 2009 15:18:11 +0100
    $date | sed "s/[^ ][^ ]*$/$($date +%z)/"
  else
    $date "$@"
  fi
}

This works fine, as far as I can tell. Is there a reason to avoid having a variable and a function with the same name?

  • 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-06-12T14:12:58+00:00Added an answer on June 12, 2026 at 2:12 pm

    It’s alright apart from being confusing. Besides, they are not the same:

    $ date=/bin/ls
    $ type date 
    date is hashed (/bin/date)
    $ type $date 
    /bin/ls is /bin/ls
    $ moo=foo
    $ type $moo 
    -bash: type: foo: not found
    $ function date() { true; }
    $ type date 
    date is a function
    date () 
    { 
    true*emphasized text*
    }
    
    $ which true 
    /bin/true
    $ type true
    true is a shell builtin
    

    Whenever you type a command, bash looks in three different places to find that command. The priority is as follows:

    1. shell builtins (help)
      • shell aliases (help alias)
      • shell functions (help function)
    2. hashed binaries files from $PATH (‘leftmost’ folders scanned first)

    Variables are prefixed with a dollar sign, which makes them different from all of the above. To compare to your example: $date and date are not the same thing. So It’s not really possible to have the same name for a variable and a function because they have different “namespaces”.

    You may find this somewhat confusing, but many scripts define “method variables” at the top of the file. e.g.

    SED=/bin/sed
    AWK=/usr/bin/awk
    GREP/usr/local/gnu/bin/grep
    

    The common thing to do is type the variable names in capitals. This is useful for two purposes (apart from being less confusing):

    1. There is no $PATH
    2. Checking that all “dependencies” are runnable

    You can’t really check like this:

    if [ "`which binary`" ]; then echo it\'s ok to continue.. ;fi
    

    Because which will give you an error if binary has not yet been hashed (found in a path folder).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following code: string date = 13.04.2012; string date2 = (DateTime.Parse(date).AddDays(1)).ToString(); This is
I have following code: hotels = models.Hotel.objects.filter( wed=True, county=hotel_main.county.id, subscriptions__end_date__gte=datetime.date.today(), subscriptions__enquiry_count__lte=F('subscriptions__tier__enquiry_limit'), ).filter(Q(x=TRUE|Q(y=True)).distinct() And i
I have following code in VS2008 If Linq.Enumerable.Contains(Of String)(selectedUsersRoles, RoleCheckBox.Text) Then RoleCheckBox.Checked = True
In my .bashrc I have the following code if [`uname` == "Linux"]; then echo
I have following code for updating user's column public void UpdateLastModifiedDate(string username) { using
I have following code which call a task after every 20 min and its
Have following code: public interface ITest { string St1 { get; } } public
I have following code which is running fine, but I want to know if
I have following Code Block Which I tried to optimize in the Optimized section
I have following code: Tools::Logger.Log(string(GetLastError()), Error); GetLastError() returns a DWORD a numeric value, but

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.