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
524
votes
32 answers

Using getopts to process long and short command line options

I wish to have long and short forms of command line options invoked using my shell script. I know that getopts can be used, but like in Perl, I have not been able to do the same with shell. Any ideas on how this can be done, so that I can use…
gagneet
  • 35,729
  • 29
  • 78
  • 113
501
votes
5 answers

Python argparse command line flags without arguments

How do I add an optional flag to my command line args? eg. so I can write python myprog.py or python myprog.py -w I tried parser.add_argument('-w') But I just get an error message saying Usage [-w W] error: argument -w: expected one…
interstar
  • 26,048
  • 36
  • 112
  • 180
437
votes
5 answers

Accessing bash command line args $@ vs $*

In many SO questions and bash tutorials I see that I can access command line args in bash scripts in two ways: $ ~ >cat testargs.sh #!/bin/bash echo "you passed me" $* echo "you passed me" $@ Which results in: $ ~> bash testargs.sh arg1 arg2 you…
oz123
  • 27,559
  • 27
  • 125
  • 187
388
votes
18 answers

What is the "String args[]" parameter in the main method?

What does the following Java code mean? public static void main(String[] args) What is String[] args? When would you use these args? Source code and/or examples are preferred over abstract explanations.
freddiefujiwara
  • 57,041
  • 28
  • 76
  • 106
369
votes
15 answers

Downloading MySQL dump from command line

I am moving away from Linode because I don't have the Linux sysadmin skills necessary; before I complete the transition to a more noob-friendly service, I need to download the contents of a MySQL database. Is there a way I can do this from the…
Phillip Copley
  • 4,238
  • 4
  • 21
  • 38
357
votes
11 answers

Is there a "standard" format for command line/shell help text?

If not, is there a de facto standard? Basically I'm writing a command line help text like so: usage: app_name [options] required_input required_input2 options: -a, --argument Does something -b required Does something with…
Yifan
  • 4,867
  • 5
  • 25
  • 24
354
votes
8 answers

How to export and import a .sql file from command line with options?

Not Duplicate! looking for some feature have phpmyadmin during export in command line I want to export and import a .sql file to and from a MySQL database from command line. Is there any command to export .sql file in MySQL? Then how do I import…
AZinkey
  • 5,209
  • 5
  • 28
  • 46
345
votes
15 answers

What's the best way to parse command line arguments?

What's the easiest, tersest, and most flexible method or library for parsing Python command line arguments?
kamens
  • 11,910
  • 6
  • 45
  • 46
292
votes
7 answers

How can I disable the Maven Javadoc plugin from the command line?

In pom.xml I have declaration like this org.apache.maven.plugins maven-javadoc-plugin attach-javadocs
IAdapter
  • 62,595
  • 73
  • 179
  • 242
286
votes
11 answers

How can I pass variable to ansible playbook in the command line?

How can one pass variable to ansible playbook in the command line? The following command didn't work: $ ansible-playbook -i '10.0.0.1,' yada-yada.yml --tags 'loaddata' django_fixtures="tile_colors" Where django_fixtures is my variable.
Édouard Lopez
  • 40,270
  • 28
  • 126
  • 178
276
votes
0 answers

Pass ALL Arguments from Bash Script to Another Command

What is the simplest way to grab all the given arguments for a bash script and pass them all into another command within the script? For example: Command Line: ./runProgram.sh [ARGS HERE] Script: #! /bin/bash cd bin/ java com.myserver.Program [ARGS…
Urda
  • 5,460
  • 5
  • 34
  • 47
261
votes
26 answers

How do I parse command line arguments in Scala?

What is a good way of parsing command line arguments in Scala? Related: How do I parse command line arguments in Java?
Eugene Yokota
  • 94,654
  • 45
  • 215
  • 319
254
votes
8 answers

How to pass arguments to Shell Script through docker run

I am new to the docker world. I have to invoke a shell script that takes command line arguments through a docker container. Ex: My shell script looks like: #!bin/bash echo $1 Dockerfile looks like this: FROM ubuntu:14.04 COPY ./file.sh / CMD…
Akash Mehta
  • 2,779
  • 2
  • 15
  • 10
228
votes
12 answers

How do I use the lines of a file as arguments of a command?

Say, I have a file foo.txt specifying N arguments arg1 arg2 ... argN which I need to pass to the command my_command How do I use the lines of a file as arguments of a command?
Yoo
  • 17,526
  • 6
  • 41
  • 47
219
votes
3 answers

what is docker run -it flag?

I was doing some complex stuff with docker, but as turn out I don't know what -it flag means. Recently I've come across on some example of docker run command which has confused me a little. docker run -itd ubuntu:xenial /bin/bash My question is…
Alex
  • 3,923
  • 3
  • 25
  • 43