I know if you enclose a variable (that contains a filename) with double quotes, it will expand $, *s and backticks ('). For example cmp "$file1" "$file2" will be fine if both files contain *s at the beginning or anything else that’s “normal”. It won’t work if the files have any number of dashes in the beginning though. Instead, it will try to do the literal meaning of -, treating it as an option. How do you get around this?
This will work:
var1=*file.txt
var2=*file2.txt
cmp "$var1" "$var2"
But
var1=-file.txt
cmp "$var1" "$var2"
will say – is an unrecognized option. Any ideas?
Most shell commands support a — option to tell them that the remainder of the line are actual arguments, not options.