Earlier quoted context omitted.
The short flags are really there for when you're doing things interactively. For scripts that are read and executed more often than they're written or changed, the long flags really help ensure you don't fat-finger. I'm accustomed to typing `rm -rf` when really I just need `rm -r` in a lot of cases, and in PRs it's very easy for your eyes to glaze over when there's more than a single short flag.
You literally always need -f with -r in a script (unless you want rm to prompt the user), though...
Use long flags when scripting (2013)
131–140 of 197 posts
Re: Use long flags when scripting (2013)
#132Earlier quoted context omitted.
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.
As does Python, which drives me crazy. -V is version on Python.
Re: Use long flags when scripting (2013)
#133Great 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…
I think you're assuming a level of Unix knowledge that less and less new people in the field are going to have.
Re: Use long flags when scripting (2013)
#134Earlier quoted context omitted.
These two commands should fit most of your use cases: 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.
Exactly, these are the only ones I know and never get confused. Actually I use cvzf and xvzf.
Re: Use long flags when scripting (2013)
#135If you're trying to stick to the POSIX standard, you have to use short options for standard commands like grep, since the long options are GNU extensions.
I've given up trying to be as pure and standard as possible. I could write all my scripts to use `sh`, but `bash` can make things far easier, and in my docker containers is often required by some other package anyway, so may as well just own it.
Re: Use long flags when scripting (2013)
#136Earlier quoted context omitted.
Unless you count things like Makefiles, I don't think I've ever written or encountered a "script" that was intended for use on multiple *nix flavors. This strikes me as a YAGNI situation: do it if it comes up, but not before.
This attitude is definitely something that makes my life harder. My OS is usually OpenBSD, and I constantly need to fix other people's scripts. It's not difficult to do, but it is annoying. I don't blame people for ignorance, but it'd be nice if people thought about portability. Non-portable scripts can also bite you on Linux, where Debian, for example, will swap out the shell from bash to dash for performance. but o…
Re: Use long flags when scripting (2013)
#137Re: Use long flags when scripting (2013)
#138Great 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)
#139Earlier quoted context omitted.
I think you are right, for all "exotic" tools, long flags are much better and future proof. For regular tools, short flags are so common that they are probably ok.
Your regular tool is not my regular tool. Hell, maybe my regular tool today is not going to be all that regular in 3 years.
Re: Use long flags when scripting (2013)
#140Absolutely not. Long flags are non-standard and non-portable. Don't write GNU scripts - write shell scripts.