Earlier quoted context omitted.
tar is one of the worst. I think I know what those do without looking it up but I think most people look at that with bewilderment. Randall Munroe is always helpful in these matters and has this to say: https://xkcd.com/1168/
I remember 90% of the time which flag I want to use, but the other 10% sends me into a rage! =) I gave up and added this to my .bashrc: function extract() { if [ -f $1 ] ; then case $1 in *.tar.bz2) tar xvjf $1 ;; *.tar.gz) tar xvzf $1 ;; *.bz2) bunzip2 $1 ;; *.rar) unrar x $1 ;; *.gz) gunzip $1 ;; *.tar) tar xvf $1 ;; *.tbz2) tar xvjf $1 ;; *.tgz) tar xvzf $1 ;; *.zip) unzip $1 ;; *.Z) uncompress $1 ;; *.7z) 7z x $1…
Use long flags when scripting (2013)
91–100 of 197 posts
Re: Use long flags when scripting (2013)
#92Earlier quoted context omitted.
As does Python, which drives me crazy. -V is version on Python.
Very annoying. Java HotSpot uses -version , rather than --version , which is even worse. Don't mess with the standard long-form flag!
Re: Use long flags when scripting (2013)
#93Earlier quoted context omitted.
I agree. To me, "sed -e" is an expression as a whole, and replacing -e with --expression is on the same level as aliasing "sed" to "stream-editor". Though I would make the list of "allowed" short flags very short. I can't think of many more than the ones you listed: mkdir -p sh -c cp -r tar -xaf tar -caf
tar is one of the worst. I think I know what those do without looking it up but I think most people look at that with bewilderment. Randall Munroe is always helpful in these matters and has this to say: https://xkcd.com/1168/
tar cf dir.tar dir # mnemonic: 'create file'
tar xf dir.tar(.gz|bz2|...) # mnemonic: 'eXtract file'
On systems with "modern" versions of tar `-x` is capable of recognizing which compression format is used and doesn't require the explicit `-j/z` flags you usually see.Re: Use long flags when scripting (2013)
#94Great suggestion, but I'd go for a middle ground: use long flags for the long tail, but short flags are fine for stuff that's very commonly used. I think I'll continue to write these: grep -i rm -rf ln -s gzip -v sed -e instead of: grep --ignore-case rm --recursive --force ln --symbolic gzip --verbose sed --expression If you're working on shell scripts, you probably know certain short flags well enough that long flag…
Also is typing that much of a chore?
Re: Use long flags when scripting (2013)
#95Great suggestion, but I'd go for a middle ground: use long flags for the long tail, but short flags are fine for stuff that's very commonly used. I think I'll continue to write these: grep -i rm -rf ln -s gzip -v sed -e instead of: grep --ignore-case rm --recursive --force ln --symbolic gzip --verbose sed --expression If you're working on shell scripts, you probably know certain short flags well enough that long flag…
Re: Use long flags when scripting (2013)
#96`rm -rf` is much more recognizable than `rm --recursive --force`. `tar -cvf` is much more recognizable than `tar --create --verbose --file`. Moreover, why are you writing a shell script if it's NOT quick and dirty?
Re: Use long flags when scripting (2013)
#97Earlier quoted context omitted.
Long flags aren’t just for readability, they also add entropy which contributes defensiveness against typos.
Related to this, they're less likely to do something unexpected. Many programs use -v as a short flag for --version , but some (such as curl) use it as short for --verbose Probably something you'd catch pretty quickly, but still.
Re: Use long flags when scripting (2013)
#98As the saying goes, code is typically written once and read thousands of times. It takes you less than a second to write the full flag name (add a few seconds if you need to look it up), but it will likely save at least a few hundred readings the time to look up the flag if they do not already know it. In addition, full flag names contributes "self-documentation" in many cases, and also potentially makes searching ea…
You're assuming the long version is more well known than the short version. That's a wildly and provably false assumption. Do you know, without referring to the manpage, exactly what `cp --no-dereference --preserve=links --recursive --preserve=all` does? I don't. I can take some guesses based on the names of the options, but those guesses could very easily miss an important corner case. Do you know what `cp -a` does?…
Re: Use long flags when scripting (2013)
#99Long form also allows me to find things faster in man pages.