Live data from Hacker News

Use long flags when scripting

thechangelog.com

11–20 of 133 posts

Re: Use long flags when scripting

#12
post #3

Ironically, tab-completion works on the command-line for long options, but not in a script (I'm sure vim can do it though).

Which is entirely dependent on how the shell is configured (not all shells have tab-completion for option flags, let alone path or command completion). I'm sure Vim or Emacs could do tab-completion for script flags, but you'd be in the same boat in the beginning: Someone has to script it first.

Re: Use long flags when scripting

#15
Or, there should be an automated tool that takes scripts with short flags and displays them with automatically replaced equivalent long flags for readability.

Not everything has to be static text, one format does not fit all situations.

Re: Use long flags when scripting

#16
post #9

No. Use standard POSIX flags to invoke standard POSIX functionality, so your scripts don't break when run on a different system.

I think, like most things, this would depend on who your audience is. For internal use only where you're running under a consistent environment at all times and aren't worried about portability, it probably makes sense to go with the more explicit long options.

For something you're planning to deploy to customers, it probably makes sense to play it pretty strict with POSIX.

Likewise, I usually script straight sh for portability if it's going to a customer unless there's a compelling reason to use bash. I'll mix in bash in stuff I write for myself where it makes my life simpler.

Re: Use long flags when scripting

#17
As a part-time scripter (is there any other kind?) I'm ashamed to say that I often use shortcut flags because I looked up the functionality I needed and copy pasted without taking the time to even understand what all of the flags mean.

This advice is good not only for others but setting a standard for yourself where you take a moment to learn what exactly is going on.

Re: Use long flags when scripting

#19

Disagree. There isn't and shouldn't be any hard fast rule for this. Same as most things in programming. Do what makes sense. Also, [0-9.] not [0-9\.]

IMHO, if your intent is to capture a literal dot then you should escape it even if, based on the context, you don't have to.
Post reply on HN