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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:02:33+00:00 2026-05-16T21:02:33+00:00

In my script, how can I distinguish when the asterisk wildcard character was used

  • 0

In my script, how can I distinguish when the asterisk wildcard character was used instead of strongly typed parameters?

This

# myscript *

from this

# myscript p1 p2 p3 ... (where parameters are unknown number)
  • 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-16T21:02:33+00:00Added an answer on May 16, 2026 at 9:02 pm

    The shell expands the wildcard. By the time a script is run, the wildcard has been expanded, and there is no way a script can tell whether the arguments were a wildcard or an explicit list.

    Which means that your script will need help from something else which is not a script. Specifically, something which is run before command-line processing. That something is an alias. This is your alias

    alias myscript='set -f; globstopper /usr/bin/myscript'
    

    What this does is set up an alias called ‘myscript’, so when someone types ‘myscript’, this is what gets run. The alias does two things: firstly, it turns off wildcard expansion with set -f, then it runs a function called globstopper, passing in the path to your script, and the rest of the command-line arguments.

    So what’s the globstopper function? This:

    globstopper() {
      if [[ "$2" == "*" ]]
        then echo "You cannot use a wildcard"
        return
      fi
      set +f
      "$@";
    }
    

    This function does three things. Firstly, it checks to see if the argument to the script is a wildcard (caveat: it only checks the first argument, and it only checks to see if it’s a simple star; extending this to cover more cases is left as an exercise to the reader). Secondly, it switches wildcard expansion back on. Lastly, it runs the original command.

    For this to work, you do need to be able to set up the alias and the shell function in the user’s shell, and require your users to use the alias, not the script. But if you can do that, it ought to work.

    I should add that i am leaning heavily on the resplendent Simon Tatham’s essay ‘Magic Aliases: A Layering Loophole in the Bourne Shell‘ here.

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

Sidebar

Related Questions

EDIT: The entire code and database creation script can be found from http://gitorious.org/scheator .
Here is a blog post from Kirk Munro that explains how a script can
Hi and Good day to all, Google App Script can be used in so
I have a Python3 script that can take optional command line parameters which the
I'm maintaining a script that can get its input from various sources, and works
this bash script can catch all the environment variables which are set when data
I'm running a Powershell test script from a C# application. The script can fail
I have script.sh that must be run as user2. However, this script can only
Is there any way a script can be made that copies files from a
Software packages with a configure script can specify this manually by adding --prefix: ./configure

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.