D
D
Dmitry Artemov2018-03-15 21:34:16
System administration
Dmitry Artemov, 2018-03-15 21:34:16

What are command line "switches" and what are they for?

Good day, dear users of the resource. I'm here for the first time and I want to ask the first question: What are "switches" on the command line (and also used in scripts) and what are they for? (-l -v -t etc.)
Did I google? Yes. But on my repeated requests, I did not find what I was looking for. Thank you in advance for your answer)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
1
15432, 2018-03-15
@headwalker

Yes, just text parameters that the program sees and does something depending on what parameters were passed.
For example, a console program needs to take two file names as input - where to read from and where to write.
The developer can say, they say, first write the name of the input file, and then the name of the output. And you will have to call the program like this:
And another developer will take it and think - can he make it possible to submit parameters in any order? This is where the "keys" come to the rescue. For example, the developer will "parse" the input parameters of the console program, and if he sees the "-i" parameter, then the one following it will be parsed as the name of the input file. Similarly, by the "-o" parameter, the program will understand that the name of the output file follows. These auxiliary parameters are called keys. By convention, it is common to use clear single-letter abbreviations preceded by a single dash (-i as input, -o as output) or multi-letter abbreviations preceded by two dashes (--input or --output).
And now you can call the program as
and
For two parameters, the effect is not very noticeable, but imagine that there are a dozen of them, and some of them are optional. It’s already hard to remember what to serve in what order without keys

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question