2

I have a shell bash script wich should pass the star ["*"] wildcard character to an application without using quotation marks. I am reading since hours and always find to use "set -f" inside the callings shell script, but this does nothing. May be I've misunderstood something, but I do not see what.

I am writing a C# app with the mono framework and my call inside bash is like this:

#!/bin/bash
set -f
mono app.exe "$@"

My shell script named "runit" will be used like this:

runit *

Can someone probably shed some light on this? I even tried to output the active shell options from this script, but nothing is shown.

1 Answer 1

1

With

#!/bin/bash
set -f
mono app.exe "$@"

set -f has no effect because the double-quoted argument array ( "$@" ) undergoes no further expansions.

If "$@" contains an argument whose value is *, it will get through to mono app.exe unchanged.

The problem is, that the shell calling this wrapper script will want to expand the asterisk, as set +f is the default.

You'll need to set -f in this calling shell rather than in the wrapper.


With set +f (default), backslash (\*) is another alternative to quoting ('*' or "*") that you might want to consider.

8
  • Thanks ! Are shells out there, wich are simpler ?? I started to hate bash. Waht about c-shell ? For my case, I would have to write three programs, instead of one. I shortly read an article from a shell-guru, what all could be made wrong. This was there long, that my consequence was: If nearly everything is wrong, then the sHELL must be wrong :-( What about globally setting "-f" generally for my shell ? Commented Jun 9, 2016 at 0:53
  • dash is simpler, and you can pretty much learn it from its manpage. This globbing part is common to both, however. And yes, as I've already, mentioned, you can set -f in your interactive shell if you don't want globbing. Commented Jun 9, 2016 at 1:02
  • After starting to try different shells, I saw something similar in a ZSH discussion. This led me to: >alias runit="set -f; runit" So "runit *" works perfectly for the moment. Commented Jun 9, 2016 at 5:19
  • 2
    Disabling globbing will cause more problems than it solves. Unix programs generally don't expand wildcards themselves, they rely on the shell to do it for them (with globbing). Using dash as an interactive shell is a terrible idea - it has none of the usability features like command-line history recall & editing. BTW, if nearly everything seems wrong, it's most likely that there are one or more fundamental concepts that you haven't learnt yet - like the fact that wildcards are expanded by the shell, not by individual programs. Learn the fundamentals and all will make sense. Commented Jun 9, 2016 at 6:00
  • 1
    Two more fundamental concepts are escaping and quoting. If a character like * has a special meaning, you can "escape" or disable that special meaning with a backslash, e.g. runit \*. Or with quotes, e.g. runit '*' Commented Jun 9, 2016 at 6:02

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.