0

As I understand it:

  • ./filename executes filename as a script.
  • ./ indicates the current directory.

What purpose (if any) does the ./ serve if precedes a glob qualifier (filter):

qpdf --empty --pages ./*.pdf(nOn) -- output.pdf

The question is posed because execution without the ./ seems to produce the same result.

gatorback
  • 1,384
  • 23
  • 48

2 Answers2

2

Prefixing ./ (or any path) prevents filenames starting with a dash from being taken as options.

$ touch ./-l foo bar
$ ls
bar  foo  -l
$ ls *
-rw-r--r-- 1 ilkkachu ilkkachu 0 Nov  3 15:10 bar
-rw-r--r-- 1 ilkkachu ilkkachu 0 Nov  3 15:10 foo

The root issue is that it's the shell that expands the wildcard, and when e.g. ls sees the argument -l, it can't know if it came from a filename wildcard, or if the user wrote it by hand.

Above, the file called -l caused ls to switch to the long listing. Another such filename could have ended up with an invalid option error. Or worse, if the command was rm, and you had a file called -rf.

That's just one of the issues that's arguably "wrong" with the relaxed attitude Unix systems take on file names. For more than you want to know, see e.g. these essays from David Wheeler:

ilkkachu
  • 138,973
1

The dot-slash construct doesn't "execute filename as a script" - it is a directive to the shell (or whatever other program is interpreting the input) to "look in the current directory". It is most often prepended to a command (binary or script) when that command is in the current working directory and when the current working directory is not in the search path. Using it within a command (as in your qpdf example) is a way to get source files from a different directory when you expect output files to drop into the directory you're in when you invoke the command.

John
  • 17,011