Questions tagged [options]
Passing options like -l or --word to commands, or parsing them in scripts.
67
questions
497
votes
10
answers
213k
views
How do I delete a file whose name begins with "-" (hyphen a.k.a. dash or minus)?
How do you remove a file whose filename begins with a dash (hyphen or minus) -? I'm ssh'd into a remote OSX server and I have this file in my directory:
tohru:~ $ ls -l
total 8
-rw-r--r-- 1 me ...
74
votes
5
answers
64k
views
getopt, getopts or manual parsing - what to use when I want to support both short and long options?
Currently I'm writing a Bash script which has the following requirements:
it should run on a wide variety of Unix/Linux platforms
it should support both short and (GNU) long options
I know that ...
54
votes
6
answers
30k
views
Single dashes `-` for single-character options, but double dashes `--` for words?
Where did the convention of using single dashes for letters and doubles dashes for words come from and why is continued to be used?
For example if I type in ls --help, you see:
-a, --all ...
33
votes
2
answers
3k
views
Security implications of running perl -ne '...' *
Apparently, running:
perl -n -e 'some perl code' *
Or
find . ... -exec perl -n -e '...' {} +
(same with -p instead of -n)
Or
perl -e 'some code using <>' *
often found in one-liners ...
31
votes
2
answers
40k
views
What is the difference between "du -sh *" and "du -sh ./*"?
What's the difference between du -sh * and du -sh ./* ?
Note: What interests me is the * and ./* parts.
26
votes
4
answers
51k
views
How do I handle switches in a shell script?
Are there some built-in tools that will recognize -x and --xxxx as switches (flags or "boolean options", rather than "ordinary arguments"), or do you have to go through all the ...
15
votes
1
answer
52k
views
Provide two arguments to one option using getopts
In below code when I give option r then getopts requires one arguments:
while getopts ":hr::l:" opt; do
case $opt in
r ) echo "Run Numbers - argument = $OPTARG " ;;
l ) echo "...
174
votes
4
answers
303k
views
How can I execute local script on remote machine and include arguments?
I have written a script that runs fine when executed locally:
./sysMole -time Aug 18 18
The arguments "-time", "Aug", "18", and "18" are successfully passed on to the script.
Now, this script is ...
63
votes
4
answers
11k
views
Where is the `--` (double dash) argument documented?
There are some utilities that accept a -- (double dash) as the signal for "end of options", required when a file name starts with a dash:
$ echo "Hello World!" >-file
$ cat -- -file
Hello World!
...
46
votes
7
answers
4k
views
Is `-` used only with cd?
cd - can switch between current dir and previous dir.
It seems that I have seen - used as arguments to other commands before, though I don't remember if - means the same as with cd.
I found that - ...
37
votes
2
answers
9k
views
Do command line options take an equals sign between option name and value?
Just using kubectl as an example, I note that
kubectl run --image nginx ...
and
kubectl run --image=nginx ...
both work.
For command-line programs in general, is there a rule about whether an equals ...
33
votes
8
answers
4k
views
Is there way to see `man` document only for specified option of a command
If I want to know the meaning of wget -b, I see the manual by man wget, then search the -b option.
-b
--background
Go to background immediately after startup. If no output file is ...
38
votes
1
answer
47k
views
Do you need to specify the "defaults" option in fstab?
The Arch Wiki on fstab specifies the options of / to be defaults,noatime, but on my installation the default fstab is created with the options of rw,relatime. The Arch Wiki covers the atime issues. ...
6
votes
1
answer
2k
views
Mapping metadata with avconv does not work
The way I understand man avconv (version 9.16-6:9.16-0ubuntu0.14.04.1), the following command should convert input.ogg to output.mp3 and carry over metadata:
avconv -i input.ogg -map_metadata 0 ...
0
votes
2
answers
6k
views
Can you make a bash script's option arguments be optional?
I would like either of these inputs to work. That is, the -n option itself is optional – I already know how to do that – but it then may have an optional parameter on top. If no parameter is given, a ...