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
122
votes
4 answers

Bash command line and input limit

Is there some sort of character limit imposed in bash (or other shells) for how long an input can be? If so, what is that character limit? I.e. Is it possible to write a command in bash that is too long for the command line to execute? If there is…
Derek Halden
  • 2,223
  • 4
  • 17
  • 26
120
votes
6 answers

How to load program reading stdin and taking parameters in gdb?

I have a program that takes input from stdin and also takes some parameters from command line. It looks like this: cat input.txt > myprogram -path "/home/user/work" I try to debug the code with gdb inside emacs, by M-x gdb, I try to load…
vinc456
  • 2,862
  • 5
  • 23
  • 30
115
votes
4 answers

How to change a command line argument in Bash?

Is there a way to change the command line arguments in a Bash script? For example, a Bash script is invoked like this: ./foo arg1 arg2 Is there a way to change the value of arg1 within the script? Something like: $1="chintz"
Sriram
  • 10,298
  • 21
  • 83
  • 136
114
votes
2 answers

What is Robocopy's "restartable" option?

robocopy /Z = "copy files in restartable mode". What does this option do? All the documentation I've found simply quotes the on-board manual. What is "restartable" mode, why would someone use it, and how does it differ from "Backup mode" (/B) ?
user2279887
  • 1,191
  • 2
  • 8
  • 7
110
votes
5 answers

What is the format for --date parameter of git commit

I need to overwrite the date of the commit of Git, all the documentation points to --date parameter, but then leaves one without a clue to the appropriate format. I've tried every permutation I can think of, and i'm getting: "fatal: invalid date…
v010dya
  • 5,296
  • 7
  • 28
  • 48
108
votes
12 answers

How to parse multiple nested sub-commands using python argparse?

I am implementing a command line program which has interface like this: cmd [GLOBAL_OPTIONS] {command [COMMAND_OPTS]} [{command [COMMAND_OPTS]} ...] I have gone through the argparse documentation. I can implement GLOBAL_OPTIONS as optional argument…
Vikas
  • 8,790
  • 4
  • 38
  • 48
104
votes
9 answers

How to give arguments to kill via pipe

I need to search for a certain process and kill that process. I wrote a command like this: ps -e | grep dmn | awk '{print $1}' | kill Where the process name is dmn. But it is not working. How can I find processes by name and kill them.
user567879
  • 5,139
  • 20
  • 71
  • 105
100
votes
1 answer

What's the difference between --add-exports and --add-opens in Java 9?

Java 9 (jdk-9+170) does not allow by default an application to see all classes from the JDK, unlike all previous versions of Java, due to the new module system. To workaround this, the java command line offers a new argument --add-exports which…
99
votes
2 answers

How do you specify command line arguments in Xcode 4?

I just upgraded to Xcode 4 and can't find much documentation on it yet, since it just went gold master. I need to specify a command line argument for testing my application. The Xcode 3.2 advice doesn't help since everything got moved around.
Joshua Olson
  • 3,675
  • 3
  • 27
  • 30
99
votes
6 answers

Java: Check if command line arguments are null

I am looking to do some error checking for my command line arguments public static void main(String[] args) { if(args[0] == null) { System.out.println("Proper Usage is: java program filename"); System.exit(0); …
Bobby S
  • 4,006
  • 9
  • 42
  • 61
97
votes
12 answers

Windows is not passing command line arguments to Python programs executed from the shell

I'm having trouble getting command line arguments passed to Python programs if I try to execute them directly as executable commands from a Windows command shell. For example, if I have this program (test.py): import sys print "Args: %r" %…
mckoss
  • 6,764
  • 6
  • 33
  • 31
89
votes
14 answers

Pass a variable to a PHP script running from the command line

I have a PHP file that is needed to be run from the command line (via crontab). I need to pass type=daily to the file, but I don't know how. I tried: php myfile.php?type=daily but this error was returned: Could not open input file:…
hd.
  • 17,596
  • 46
  • 115
  • 165
85
votes
17 answers

xargs with multiple arguments

I have a source input, input.txt a.txt b.txt c.txt I want to feed these input into a program as the following: my-program --file=a.txt --file=b.txt --file=c.txt So I try to use xargs, but with no luck. cat input.txt | xargs -i echo "my-program…
Howard
  • 19,215
  • 35
  • 112
  • 184
85
votes
8 answers

How to convert a command-line argument to int?

I need to get an argument and convert it to an int. Here is my code so far: #include using namespace std; int main(int argc,int argvx[]) { int i=1; int answer = 23; int temp; // decode arguments if(argc < 2) { …
nosedive25
  • 2,477
  • 5
  • 30
  • 45
84
votes
6 answers

How to capture arguments passed to a Groovy script?

I am just starting out with Groovy. I couldn't find any examples anywhere of how to handle arguments to a Groovy script and so I hacked this method myself. There must be a better way of doing this? If so, I am looking for this better way, since…
djangofan
  • 28,471
  • 61
  • 196
  • 289