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

  • Home
  • SEARCH
  • 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 9177517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:20:39+00:00 2026-06-17T17:20:39+00:00

Is it possible to source a Bash snippet, but only actually provide a function

  • 0

Is it possible to source a Bash snippet, but only actually provide a function from inside it if a certain condition holds true?

So what I am asking is that I can unconditionally source all files from a directory, but the sourced files contain the logic to provide functions to the sourcing shell or not.

Example:

  • .bashrc sources whole sub folder .bashrc.d
  • .bashrc.d/xyz provides a function adduser2group which works on old systems where usermod doesn’t handle -a -G
  • .bashrc.d/xyz should provide that function only to the sourcing shell if it’s running on such old system.

My current method is to conditionally create an alias named adduser after the Debian program (alias adduser=adduser2group). So I only implement the adduser <user> <group> semantics, but still it’s helpful.

Is there a solution that doesn’t require this workaround? After all this method means a chance for name clashes which I’d prefer to avoid.

  • 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-17T17:20:40+00:00Added an answer on June 17, 2026 at 5:20 pm

    You can define the functions you want and, whenever a particular condition holds, you just unset the function:

    $ function alpha() { echo $1; }
    $ alpha 10
    10
    

    Evaluating your condition — and considering it holds true:

    $ if [[ your condition ]]; then unset alpha; fi
    $ alpha 10
    alpha: command not found
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What all possible support is there from open source world for building web based
Is it possible to download source code from a github public project before a
I have sourced a script in bash source somescript.sh . Is it possible to
Is it possible to source a file without printing all the charts etc (already
Possible Duplicate: How to protect my source code when deployed? Can you give me
Possible duplicate What is the best open source example of a lightweight Windows Application?
It's possible to get the source of the location data (for example GPS receiver,
Is it possible to open an SQL scrapbook with the Data Source Explorer in
Is it possible to make a Java program that prints its source code to
Is it possible to specify a web service as the source for an iFrame?

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.