News for hackers. Stuff that matters.
Re:./watch by Y_Y on Saturday October 18, 2025 @07:26AM (#45626483)
On that point, I see an awful lot of code that uses dotslash as if it was necessary for files in the current directory.

You only need to prepend dotslash to a filename in order of disambiguate invocations of executables in the the current directory (and not a subdirectory).

This is because bare commands will be looked up in $PATH, rather than among executable files in $PWD.

It strikes me as weird copycat (without understanding) programming to just have it wherever you're referring to a local file. In fact I prefer to invoke `bash foo.sh` rather than `mv foo.sh foo; chmod +x foo.sh; ./foo.sh`. (This assumes that I don't need to rely on something special in the shebang line.) This also lets you use tab-completion as normal, as well as adding flags for bash like -x.

(I know you could use it for clarity when an argument could look like a string or a file, but I don't think that's usuaully the purpose.)

Re:./watch by PhilippGille on Saturday October 18, 2025 @07:53AM (#45626611)
One issue is when the path is not interpreted by the shell but by a program which plays by different rules.

For example in Go:

  $ cd /path/to/go/repo
  $ go run cmd/myapp
  package cmd/myapp is not in std (/usr/local/go/src/cmd/myapp)
  
  $ go run ./cmd/myapp
  Hello, World!
And then people don't want to think about when your path is for the shell and when it's a CLI param and how the CLI treats it, and just use the version that always works.
Re:./watch by Y_Y on Saturday October 18, 2025 @08:51AM (#45626951)
Thanks, this is the first good reason I've seen! Seems crazy to me that the go tool does that, but maybe I just lack sufficient unix-nature.
Re:./watch by zahlman on Saturday October 18, 2025 @09:38AM (#45627272)
This allows it to disambiguate between system path syntax and the language's syntax for symbolic names.

Similarly, package installers can use this to disambiguate between "install the local file with this exact name" and "look up a file on the index for the named package".

Re:./watch by umanwizard on Saturday October 18, 2025 @12:54PM (#45628703)
This is one of the papercuts of go that I find way more annoying than is rational.
Re:./watch by catlifeonmars on Saturday October 18, 2025 @02:02PM (#45629236)
That’s because cmd/myapp is not a local path, it’s a universal path. It makes more sense when you type go run github.com/user/name/cmd/myapp
Re:./watch by PhilippGille on Sunday October 19, 2025 @02:41PM (#45636744)
> cmd/myapp is not a local path, it’s a universal path

In `go run` the CLI interprets it as universal path, to be precise. That's exactly the point.

> go run github.com/user/name/cmd/myapp

That's not an alternative when you're working on the app's code locally. You have to use `./cmd/myapp`.

And when you do that multiple times per day/week, after a while you just start always using `./` prefix for local paths.

Re:./watch by catlifeonmars on Sunday October 19, 2025 @07:45PM (#45639017)
Would it be preferable to use a URI for go run?

For example

- go run go://cmd/foo

- go run file:///cmd/foo

Re:./watch by Bleibeidl on Saturday October 18, 2025 @07:43AM (#45626566)
I'm pretty sure most people use it to make clear it's a relative path. It takes mental load off the one reading the code. That's why I pretty much always use it, not only when executing things.
Re:./watch by aidos on Saturday October 18, 2025 @07:33AM (#45626519)
./<tab> completes nicely. Ambiguity is removed. There’s no chance of accidentally running the wrong executable.

So I think you and I differ on this one, but none of this is a hill I care to die on.

Re:./watch by amonith on Saturday October 18, 2025 @07:43AM (#45626571)
I use it for autocomplete... e.g ./f<tab> and enter. If I don't do it the terminal literally hangs for a split second and gives me a lot useless suggestions. I rarely type full words.
Re:./watch by teddyh on Saturday October 18, 2025 @07:37AM (#45626539)
Similarly, many people needlessly append a slash to every directory name.
Re:./watch by BoredPositron on Saturday October 18, 2025 @08:44AM (#45626911)
For me it's because of rsync.
Re:./watch by chuckadams on Saturday October 18, 2025 @02:21PM (#45629360)
It's handy when the directory might not exist, happens all the time in git checkouts. Raise your hand if you've ever moved something to tmp and created a file called tmp.

Usually it's tab-complete adding the slash though, I don't go typing it in.

Re:./watch by SoftTalker on Saturday October 18, 2025 @02:39PM (#45629475)
Makes it clear you're naming a directory and not a file.

I also alias 'ls' to 'ls -F' so that directories have a / appended, makes it easier to understand the output.

Re:./watch by mjw1007 on Saturday October 18, 2025 @07:31AM (#45626507)
It makes tab completion work.
Re:./watch by jagged-chisel on Saturday October 18, 2025 @07:41AM (#45626555)
At the start of a line? So you want to run a script or executable in the current directory. PATH doesn’t contain . and ./ is necessary.

As an argument in a line? My shell offers completion from the current directory without ./ just fine.

Re:./watch by alganet on Saturday October 18, 2025 @07:55PM (#45631203)
Let's say you have 100 programs in your PATH that start with the letter "g", but only one program in the current folder that starts with "g". You type `./g[TAB]` so it autocompletes automatically to the local program instead of cycling through dozens of results you know you don't want.
Re:./watch by lynx97 on Saturday October 18, 2025 @07:34AM (#45626522)
For executables, it is actually necessary to prepend ./ iff . is not in $PATH. And . is usually not in $PATH for security reasons.