2 ms·
If we are talking about interactive use, you could always use an alias. But if we are talking about scripts, you should at least use "fgrep -- [a] < file". An
by teddyh 4y ago
If we are talking about interactive use, you could always use an alias.
But if we are talking about scripts, you should at least use "fgrep -- [a] < file". And if you’re adding an option anyway, you might as well use "grep -F -- [a] < file". Personally, I prefer using options, specifically long options, in scripts; meaning "grep --fixed-strings --regexp=[a] < file".
If you don’t do this, the script will fail spectacularly the day when the string happens to start with a hyphen (-).
- romeoblade 4y agoI thought I was the only one who perfected long options! Are you me? I've had coworkers call me out (not rude, just "hey you know you just use -l... instead of --longopt") on calls because I always use long options when available. I use the hyphen explanation all the time as I've ran into it a few times. I also prefer CLI applications that are designed to use the "=" for arguments with long options. Applications which don't use "=" or respect it, irk me because the it's ambiguous... "Is that argument an argument or sub command" when looking through history.
- teddyh 4y agoI don’t always use long options interactively, only sometimes, but I certainly try to always use it in scripts, for readability.