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
3000
votes
41 answers

How do I pass command line arguments to a Node.js program and receive them?

I have a web server written in Node.js and I would like to launch with a specific folder. I'm not sure how to access arguments in JavaScript. I'm running node like this: $ node server.js folder here server.js is my server code. Node.js help says…
milkplus
  • 33,007
  • 7
  • 30
  • 31
1212
votes
12 answers

Propagate all arguments in a Bash shell script

I am writing a very simple script that calls another script, and I need to propagate the parameters from my current script to the script I am executing. For instance, my script name is foo.sh and calls bar.sh. foo.sh: bar $1 $2 $3 $4 How can I do…
Fragsworth
  • 33,919
  • 27
  • 84
  • 97
1201
votes
21 answers

How to pass command line arguments to a rake task

I have a rake task that needs to insert a value into multiple databases. I'd like to pass this value into the rake task from the command line, or from another rake task. How can I do this?
Tilendor
  • 48,165
  • 17
  • 52
  • 58
1046
votes
27 answers

Parsing boolean values with argparse

I would like to use argparse to parse boolean command-line arguments written as "--foo True" or "--foo False". For example: my_program --my_boolean_flag False However, the following test code does not do what I would like: import argparse parser =…
SuperElectric
  • 17,548
  • 10
  • 52
  • 69
968
votes
11 answers

Check number of arguments passed to a Bash script

I would like my Bash script to print an error message if the required argument count is not met. I tried the following code: #!/bin/bash echo Script name: $0 echo $# arguments if [$# -ne 1]; then echo "illegal number of parameters" fi For…
triple fault
  • 13,410
  • 8
  • 32
  • 45
907
votes
8 answers

Passing additional variables from command line to make

Can I pass variables to a GNU Makefile as command line arguments? In other words, I want to pass some arguments which will eventually become variables in the Makefile.
Pablo
  • 28,133
  • 34
  • 125
  • 215
850
votes
31 answers

Argument list too long error for rm, cp, mv commands

I have several hundred PDFs under a directory in UNIX. The names of the PDFs are really long (approx. 60 chars). When I try to delete all PDFs together using the following command: rm -f *.pdf I get the following error: /bin/rm: cannot execute…
Vicky
  • 16,679
  • 54
  • 139
  • 232
791
votes
22 answers

How can I read and process (parse) command line arguments?

In Python, how can we find out the command line arguments that were provided for a script, and process them? Related background reading: What does "sys.argv[1]" mean? (What is sys.argv, and where does it come from?). For some more specific…
edgerA
731
votes
20 answers

Best way to parse command line arguments in C#?

When building console applications that take parameters, you can use the arguments passed to Main(string[] args). In the past I've simply indexed/looped that array and done a few regular expressions to extract the values. However, when the commands…
Paul Stovell
  • 32,377
  • 16
  • 80
  • 108
681
votes
21 answers

How do I parse command line arguments in Java?

What is a good way of parsing command line arguments in Java?
lindelof
  • 34,556
  • 31
  • 99
  • 140
679
votes
13 answers

What does int argc, char *argv[] mean?

In many C++ IDE's and compilers, when it generates the main function for you, it looks like this: int main(int argc, char *argv[]) When I code C++ without an IDE, just with a command line compiler, I type: int main() without any parameters. What…
Greg Treleaven
  • 8,124
  • 7
  • 30
  • 30
646
votes
9 answers

How do I run a program with commandline arguments using GDB within a Bash script?

When running a program on GDB, usually, the arguments for the program are given at the run command. Is there a way to run the program using GDB and as well as give arguments within a shell script? I saw an answer in a related question, mentioning…
drox
  • 7,523
  • 4
  • 23
  • 34
620
votes
12 answers

User input and command line arguments

How do I have a Python script that can accept user input and how do I make it read in arguments if run from the command line?
Teifion
  • 108,121
  • 75
  • 161
  • 195
620
votes
11 answers

How do I access command line arguments?

I use python to create my project settings setup, but I need help getting the command line arguments. I tried this on the terminal: $python myfile.py var1 var2 var3 In my Python file, I want to use all variables that are input.
ParisNakitaKejser
  • 12,112
  • 9
  • 46
  • 66
603
votes
1 answer

How to handle command-line arguments in PowerShell

What is the "best" way to handle command-line arguments? It seems like there are several answers on what the "best" way is and as a result I am stuck on how to handle something as simple as: script.ps1 /n name /d domain AND script.ps1 /d domain /n…
Aaron Wurthmann
  • 6,367
  • 5
  • 21
  • 14
1
2 3
99 100