2

I know from this SO answer that naked dashes are used by various Unix utilities to specify that the user wants to use stdin or stdout instead of a regular file.

However, that doesn't quite help me understand the syntax of the following (which I took from a Heroku buildpack that basically installs a copy of Perl in a directory). Overall what's happening is that Perl is being downloaded from a URL at $PERL_PACKAGE and piped to tar, which extracts it to the directory $VENDORED_PERL

curl $PERL_PACKAGE -s -o - | tar xzf - -C $VENDORED_PERL

But the details are kind of confusing. -o is used when you want to specify a file for output instead of stdout, so I don't see why you'd use that option and then a dash, instead of just not using the option at all.

As for tar, I guess - is telling it not to use an input file since it's receiving the input from a pipe?

Maybe I'm missing some of the requirements of how pipes work.

2 Answers 2

2

f - means "read from stdin" / "write to stdout" with tar, too. But the default source / target may vary between tar versions and implementations thus it seems safer to add it to the command.

If -o - is not needed for curl then maybe the author of that command did not know that or thought the command was easier to understand with this explicit information.

1

I don't think you're missing anything. The options you mention are unnecessary in all the shells and curl and tar implementations that I've used in recent years.

I would write that line like this:

curl "$PERL_PACKAGE" -s | tar xz -C "$VENDORED_PERL"

That is, without the unnecessary filename options, and with conservative double-quoting of the variables used as command line arguments.

Why did they write the way they did? Could be old habits. Or some old systems, old implementations where these parameters used to be necessary. And since the script works as is, there's nothing to "fix".

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .