Questions tagged [command-line-arguments]

Programming command line utilities that take parameters.

This tag should have questions relating to programming command-line utilities that take arguments.

A command line argument is a parameter passed to a command line program. For instance git status is the Git command line program with the parameter status. Git then acts accordingly to that parameter.

Command line arguments are used in command line programs from the Command Prompt on Windows, a shell on Unix and the Terminal program on Mac OS. These are not visual GUI programs, they are text based.

Learn more: Wikipedia Article Command Line

5018 questions
84
votes
2 answers

Using command line arguments in VBscript

How can I pass and access command line arguments in VBscript?
Sunil
  • 1,941
  • 3
  • 19
  • 25
83
votes
4 answers

How to get the nth positional argument in bash?

How to get the nth positional argument in Bash, where n is variable?
hcs42
  • 13,376
  • 6
  • 41
  • 36
82
votes
7 answers

Invoke a second script with arguments from a script

I have a script that reads a configuration file that results in a set of name value pairs that I would like to pass as arguments to a function in a second PowerShell script. I do not know what parameters will be placed in this configuration file at…
81
votes
10 answers

Escape command line arguments in c#

Short version: Is it enough to wrap the argument in quotes and escape \ and " ? Code version I want to pass the command line arguments string[] args to another process using ProcessInfo.Arguments. ProcessStartInfo info = new…
hultqvist
  • 17,451
  • 15
  • 64
  • 101
81
votes
11 answers

Passing command line arguments to argv in jupyter/ipython notebook

I'm wondering if it's possible to populate sys.argv (or some other structure) with command line arguments in a jupyter/ipython notebook, similar to how it's done through a python script. For instance, if I were to run a python script as…
81
votes
2 answers

Command line arguments in Bash

I want to write a bash script which takes different arguments. It should be used like normal linux console programs: my_bash_script -p 2 -l 5 -t 20 So the value 2 should be saved in a variable called pages and the parameter l should be saved in a…
Pascal
  • 2,175
  • 4
  • 39
  • 57
76
votes
11 answers

Retrieving multiple arguments for a single option using getopts in Bash

I need help with getopts. I created a Bash script which looks like this when run: $ foo.sh -i env -d directory -s subdirectory -f file It works correctly when handling one argument from each flag. But when I invoke several arguments from each flag…
vegasbrianc
  • 989
  • 1
  • 7
  • 11
75
votes
2 answers

What is the difference between "$@" and "$*" in Bash?

It seems to me that they both store all the command-line arguments. So is there a difference between the two?
Debugger
  • 9,130
  • 17
  • 45
  • 53
75
votes
0 answers

What parameter parser libraries are there for C++?

I'd like to pass parameters on the command line to my C++ program in the following manner: ./myprog --setting=value Are there any libraries which will help me to do this easily?
Jim
  • 1,091
  • 1
  • 9
  • 11
75
votes
8 answers

Argparse: Check if any arguments have been passed

My script should start a demo mode, when the no parameters are given. I tried this: args = parser.parse_args() if len(args) == 0: run_demo() else: # evaluate args Which gives a *** TypeError: object of type 'Namespace' has no len() as args…
Framester
  • 33,341
  • 51
  • 130
  • 192
73
votes
10 answers

Get command-line arguments from spring-boot:run

Is there any way to input arguments when launching spring-boot application (mvn spring-boot:run) from commandline and then get them in main()?
sandris
  • 1,478
  • 2
  • 18
  • 34
73
votes
8 answers

cp --parents option on mac

On Linux, I have a --parents option available for the cp command so I can do cp --parents test/withintest/go.rb test2 http://www.gnu.org/software/coreutils/manual/html_node/cp-invocation.html On Mac, I do not have this option available. Is there a…
dmonopoly
  • 3,251
  • 5
  • 34
  • 49
72
votes
6 answers

Arguments to main in C

I don't know what to do! I have a great understanding of C basics. Structures, file IO, strings, etc. Everything but CLA. For some reason I cant grasp the concept. Any suggestions, help, or advice. PS I am a linux user
Anthony
  • 745
  • 1
  • 6
  • 4
69
votes
9 answers

Can command line flags in Go be set to mandatory?

Is there a way how to set that certain flags are mandatory, or do I have to check for their presence on my own?
Petr
  • 62,528
  • 13
  • 153
  • 317
67
votes
7 answers

How can I find out if an .EXE has Command-Line Options?

Suppose you have an .EXE and you want to check if it has Command-Line Options. How can one know if the .EXE has this ability. In my case I know that Nir Sofers WebBrowserPassView.exe has the ability to start it via cmd.exe and WebBrowserPassView.exe…
JohnnyFromBF
  • 9,873
  • 10
  • 45
  • 59