Earlier quoted context omitted.
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.
He's talking about thing like sed/awk/grep/find/xargs/tar not new_hotness_util_2020
Use long flags when scripting (2013)
181–190 of 197 posts
Re: Use long flags when scripting (2013)
#182In scripts, I usually do stuff like this command \ --longopt1 \ --longopt2 arg \ argument or command | \ command 2 | \ command 3 \ --opt1 \ --opt2 \ arg
If I'm splitting across lines, I prefer to put the pipe _after_ the newline. Otherwise, I like the cut of your jib, and will likely do this with arguments in scripts from now on.
foo \
--group1 \
\
--group 2 \
--more-stuff 2 \
| \
bar \
--bar-stuff
using a line with a single backlash or breaking out the pipe can make grouping stuff clear. well, I mean as clear as having to use backslashes which to me is a little inelegant. Personally python and its indenting strategy has grown on me especially since editor support makes it painless to use and visually excellent.Re: Use long flags when scripting (2013)
#183I wanted to say that Microsoft explicitly says to use the full argument label and not omit them when writing PowerShell scripts but I can't find the doc.
I was thinking that the author would really like PowerShell. PowerShell is the most verbose thing I've ever used. I don't really like to type that much for simple things. I say just learn the flags or look them up, it shouldn't be hard or time consuming. When reading scripts, many times you can infer what the flags mean by understanding the inputs and desired outputs.
Re: Use long flags when scripting (2013)
#184Earlier quoted context omitted.
Powershell? It's available for linux now
> Powershell? It's available for linux now I'd rather have my tonsils extracted through my ears. I went the other way[0] decades ago and never looked back. [0] https://www.cygwin.com
Re: Use long flags when scripting (2013)
#185This is how I write PowerShell scripts. I use full cmdlet names, full argument switch names, and I even specify argument switches to positional arguments. I also do my best to honor common flags like `-WhatIf`, `-Verbose`, and `-ErrorAction`. So I end up with scripts like this: if (-not $(Test-Path -Path "$Path" -PathType Container)) { Write-Error -Message "Path ($Path) does not exist or is not a directory." -Categor…
PS has another reason to use full names of parameters in long-lived scripts. If you use short names like `-Ver` expecting it to match `-Verbose`, a future version of the commandlet can add `-Version` and now `-Ver` is ambiguous. On the other hand, I've seen some people eschew `%` and `?` in favor of writing `ForEach-Object` and `Where-Object`, which in my opinion is too extreme in the other direction. BTW, in: if (-n…
Re: Use long flags when scripting (2013)
#186Earlier 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.
The worst (well known) offender is grep -v meaning grep --invert-match just for the sheer bafflement of "verbose" now hiding what you were looking for.
The default command was to just print the line. Hence the name grep
g/re/p
Re: Use long flags when scripting (2013)
#187Earlier quoted context omitted.
> Powershell? It's available for linux now I'd rather have my tonsils extracted through my ears. I went the other way[0] decades ago and never looked back. [0] https://www.cygwin.com
I was mostly joking. The verbosity of powershell just makes me throw up in my mouth a little time every time I have to deal with it.
But I really would recommend Cygwin[1] for anyone who needs to use Windows.
Having a real shell makes a big difference.
Re: Use long flags when scripting (2013)
#188Earlier 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/
> To disarm the bomb, simply enter a valid tar command on your first try. No Googling. You have ten seconds. $ tar --help Obviously. :)
Even better. :)
Re: Use long flags when scripting (2013)
#189Earlier quoted context omitted.
Does anyone care about the standard? Let's be honest it's outdated, has a bad UX and is with the standards I would hold such a standard against today generally not so good. Sure systems seen try to somewhat be POSIX compliance but from my experience not because they care about POSIX but because that happen to overlap with the idea to be somewhat compiland with other similar systems so that porting software/scripts is…
Yes, if you care about portability. Anything that's not Linux likely won't have GNU grep installed by default. This includes macOS and the BSDs. If this is your own dotfiles or utilities, sure, but if I'm working on something collaborative, yes, I care about the standard.
It's just way too easy to run into a unexpected gotcha on some platform/configuration.