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
211
votes
42 answers

Parsing Command Line Arguments in C++?

What is the best way of parsing command-line arguments in C++ if the program is specified to be run like this: prog [-abc] [input [output]] Is there some way of doing this built into the standard library, or do I need to write my own…
Verhogen
  • 27,221
  • 34
  • 90
  • 109
197
votes
8 answers

Run a string as a command within a Bash script

I have a Bash script that builds a string to run as a command Script: #!…
João Portela
  • 6,338
  • 7
  • 38
  • 51
165
votes
5 answers

argparse store false if unspecified

parser.add_argument('-auto', action='store_true') How can I store false if -auto is unspecified? I can faintly remember that this way, it stores None if unspecified
siamii
  • 23,374
  • 28
  • 93
  • 143
158
votes
4 answers

Passing IPython variables as arguments to bash commands

How do I execute a bash command from Ipython/Jupyter notebook passing the value of a python variable as an argument like in this example: py_var="foo" !grep py_var bar.txt (obviously I want to grep for foo and not the literal string py_var)
Unni
  • 5,348
  • 6
  • 36
  • 55
158
votes
5 answers

mkdir's "-p" option

So this doesn't seem like a terribly complicated question I have, but it's one I can't find the answer to. I'm confused about what the -p option does in Unix. I used it for a lab assignment while creating a subdirectory and then another…
151
votes
14 answers

Parsing command-line arguments in C

I'm trying to write a program that can compare two files line by line, word by word, or character by character in C. It has to be able to read in command line options -l, -w, -i or --... if the option is -l, it compares the files line by line. if…
user1251020
  • 1,529
  • 2
  • 11
  • 7
150
votes
4 answers

How do I pass a command line argument while starting up GDB in Linux?

I have to debug a program that has errors in it as part of my assignment. However, I must first pass command line arguments in order to solve this problem. I do: gdb -tui InsertionSortWithErrors which works, but after that I don't know how to pass…
ShadyBears
  • 3,955
  • 13
  • 44
  • 66
146
votes
6 answers

How do you access command line arguments in Swift?

How do you access command line arguments for a command line application in Swift?
Anthony Mittaz
  • 1,541
  • 2
  • 10
  • 7
135
votes
12 answers

Parse config files, environment, and command-line arguments, to get a single collection of options

Python's standard library has modules for configuration file parsing (configparser), environment variable reading (os.environ), and command-line argument parsing (argparse). I want to write a program that does all those, and also: Has a cascade of…
134
votes
1 answer

Transform hexadecimal information to binary using a Linux command

I have this binary file on my Linux system... udit@udit-Dabba ~ $ cat file.enc Salted__s�bO��<0�F���Jw!���]�:`C�LKȆ�l Using the hexdump command, I see its information like this: udit@udit-Dabba ~ $ hexdump -C file.enc 00000000 53 61 6c 74 65…
Udit Gupta
  • 3,162
  • 11
  • 43
  • 71
132
votes
6 answers

Passing command line arguments in Visual Studio 2010?

I am working on a C project and can not figure out how to pass command line arguments to my main function in Visual Studio 2010 Express Edition. I want to debug - how do these command line arguments work?
Fahad
  • 1,377
  • 2
  • 9
  • 6
130
votes
9 answers

How to implement the --verbose or -v option into a script?

I know the --verbose or -v from several tools and I'd like to implement this into some of my own scripts and tools. I thought of placing: if verbose: print ... through my source code, so that if a user passes the -v option, the variable verbose…
Aufwind
  • 25,310
  • 38
  • 109
  • 154
127
votes
10 answers

How to pass arguments in pytest by command line

I have a code and I need to pass the arguments like name from terminal. Here is my code and how to pass the arguments. I am getting a "File not found" kind error that I don't understand. I have tried the command in the terminal: pytest .py…
ashish sarkar
  • 1,289
  • 2
  • 9
  • 7
122
votes
10 answers

How to access command line arguments of the caller inside a function?

I'm attempting to write a function in bash that will access the scripts command line arguments, but they are replaced with the positional arguments to the function. Is there any way for the function to access the command line arguments if they…
DonGar
  • 7,344
  • 8
  • 29
  • 32
122
votes
9 answers

How can I force ssh to accept a new host fingerprint from the command line?

I'm getting the standard WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Someone could be eavesdropping on you right now (man-in-the-middle attack)! It is also possible that the RSA host key…
John O
  • 4,863
  • 8
  • 45
  • 78