Provide '*' as a CLI argument

I was trying out a calc program taking in operators and operands as cli values. Worked out for everything else except '*'.

If I run
cargo run -- 1 * 2
the * gets replaced by Cargo.toml Cargo.lock src target. Basically every file in directory. So I'm guessing run takes * as a wildcard. I'm running multiply as
cargo run -- 1 \* 2
and that seems to work. Is there a way to by pass this behavior and simply use *?

It's not cargo but the terminal emulator you're using. If you don't want expansion, wrapping params with single quotes would be another solution.


Specifically, this is a feature of your shell. See documentation for wildcards in bash, globs in zsh or Wildcards in PowerShell, for Linux, Mac and Windows respectively. (In linux, one might install zsh, or another shell, but most distributions default to bash). All of these shells have slightly different behaviors, but * is pretty globally the pattern for "zero or more characters", and all three will by default expand patterns to all filenames which match them.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.