All Questions
26
questions
1
vote
1
answer
75
views
install --compare is said to, in some cases, not modify the destination at all - but in which cases?
The man page for install describes the --compare option like so:
-C, --compare
compare each pair of source and destination files, and
in some cases, do not modify ...
3
votes
3
answers
2k
views
Replacing command line arguments while preserving spaces
I would like to selectively replace a command-line argument that is being passed to automatically format it for the downstream command being executed. The argument will have spaces and that is the ...
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!
...
0
votes
2
answers
101
views
Stop executables and built-ins from interpreting a string argument starting with - as a switch? [duplicate]
Let's say I want to search a file for a string that begins with a dash, say "-something":
grep "-something" filename.txt
This throws an error, however, because grep and other executables, as well as ...
19
votes
1
answer
2k
views
Why does -a in "#!/bin/sh -a" affect sed and "set -a" doesn't?
If I run the following .sh file:
#!/bin/sh -a
echo "a" | sed -e 's/[\d001-\d008]//g'
The result is an error:
sed: -e expression #1, char 18: Invalid range end
But if I run the following .sh file:...
2
votes
1
answer
25k
views
how to properly parse shell script flags and arguments using getopts
I'm using this :
for example ./imgSorter.sh -d directory -f format
the scripts' content is :
#!/bin/bash
while getopts ":d:f:" opt; do
case $opt in
d)
echo "-d was triggered with $...
19
votes
3
answers
4k
views
Why do options in a quoted variable fail, but work when unquoted?
I read about that I should quote variables in bash, e.g. "$foo" instead of $foo. However, while writing a script, I found an a case where it works without quotes but not with them:
wget_options='--...
2
votes
0
answers
120
views
Printing autocomplete info on current option in fish shell
When writing a command with a - option and pressing tab, a list of possible completions with short explanations of what the options do is displayed. Is there a way to make this list also contain the ...
7
votes
3
answers
2k
views
Set awk array on command line?
I know the -v switch can be used to awk on the command line to set the value for a variable.
Is there any way to set values for awk associative array elements on the command line?
Something like:
...
14
votes
3
answers
21k
views
What does the option -9 mean for killall?
I saw the command killall -9 but there is not such a option in the man page.
So now I'm a bit confused: what does -9 option mean?
2
votes
2
answers
3k
views
how to delete file that start with "-" [duplicate]
I try to delete this file on my solaris machine
rm "-Insi"
rm: illegal option -- I
rm: illegal option -- n
rm: illegal option -- s
I also try this
rm "\-Insi"
-Insi: No such file or directory
...
3
votes
1
answer
2k
views
Strange leading whitespace in OPTARG when using getopts
I spent quite a while researching the problem I encountered but none of the getopts tutorial say anything about the leading whitespace in OPTARG when using getopts.
In bash(on Ubuntu and OSX), ...
6
votes
3
answers
24k
views
Optional arguments after or before the mandatory arguments?
I'm creating a shell script and I need it to take two mandatory arguments and one optional. How do I check that? In most scripts I've seen, the optional arguments are passed before the mandatory ones, ...
0
votes
1
answer
76
views
Options to a command specified in a file
How can I have some of the options to a unix command come from a file? That is the file does not contain all the options -- other options are specified elsewhere.
For example I have the filelsoptions....
1
vote
2
answers
45
views
Shell is option given
I have a couple of arguments inside a list (array, e.g. $@) and I'd like to know if the option -v is in the list.
In Python I would simply do:
verbose = "-v" in sys.argv
How do I achieve that in ...