Live data from Hacker News

Use long flags when scripting (2013)

changelog.com

31–40 of 197 posts

Re: Use long flags when scripting (2013)

#31

Great 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…

How often do you use gzip verbose? I don't think I've ever used it. What's it good for?

Re: Use long flags when scripting (2013)

#32

Great 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…

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.

Re: Use long flags when scripting (2013)

#33
post #31

Great 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…

How often do you use gzip verbose? I don't think I've ever used it. What's it good for?

Pretty much just to make sure you're not wasting your time with the gzip.

But I also don't use gzip much these days. pbzip2 is a drop in replacement that is faster and compresses better.

Re: Use long flags when scripting (2013)

#34
post #31

Great 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…

How often do you use gzip verbose? I don't think I've ever used it. What's it good for?

Personally a fan of '--verbose' to be honest. It's clear. "grep -v" anyone?

Re: Use long flags when scripting (2013)

#35
post #31

Great 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…

How often do you use gzip verbose? I don't think I've ever used it. What's it good for?

It's useful when debugging your artifacts. It's a nice shortcut for adding a `find` after the `tar` invocation. Outside of debugging I've never seen the gzip/tar verbose output as anything other than clutter.

Re: Use long flags when scripting (2013)

#37
post #3

In scripts, I usually do stuff like this command \ --longopt1 \ --longopt2 arg \ argument or command | \ command 2 | \ command 3 \ --opt1 \ --opt2 \ arg

It's nice but you cannot comment individual lines. For that you can go one step further and use arrays: cmd=( command -x -y --bar OPTARG ARG ARG ) $cmd This works in Zsh. In Bash that would be ${cmd[@]} I think. I use this with long qemu command lines where I often modify and comment out arguments during testing.

You can comment using a hack; check this out:

  command `# a comment` \
    --longopt1 `# another comment` \
    --longopt2 arg \
    argument

Re: Use long flags when scripting (2013)

#38

It’s not just “easier for a human” but more stable over time as commands evolve, and less likely to do weird things across Unix variants. Some command-line parsers will auto-complete partial options so you’re less likely to see ambiguity errors in future versions if you picked long-form options. (This isn’t completely foolproof, e.g. a command could have "--foo" and later add "--foobar" but it does help in most cases…

> Some command-line parsers will auto-complete partial options

This sort of behaviour is tortuous, and should be against international laws.

Where _adding_ new, unrelated, options to the interface now changes or breaks the behaviour of existing calling scripts. Plus you never know which abbreviations are in use in the wild.

It makes it virtually impossible to maintain a stable interface without just freezing it long-hand.

I found this in Perl code; I believe it might be the default behaviour in the standard parser? Our developer really did like the philosophy that "the user may want 50 different ways to express the same thing".

Re: Use long flags when scripting (2013)

#40
post #34
post #31

Earlier quoted context omitted.

How often do you use gzip verbose? I don't think I've ever used it. What's it good for?

Personally a fan of '--verbose' to be honest. It's clear. "grep -v" anyone?

Particularly in this case, because `-v` sometimes means "print out the version number".
Post reply on HN