Songkeys

Songkeys

Hello. Songkeys here~ :D
twitter

Mystery Solved - After entering `??` in the terminal, Golang popped up.

This text is translated by GPT-4. The original text is in English and can be viewed here.

This is not an April Fool's joke!

If you have Golang installed, you can now try opening your terminal and typing ??. You will find that it magically turns into the Golang CLI.

image

That's right! This is indeed the go command! It's as real as it gets.

image

Why is this happening?

The Beginning of the Story: GitHub Copilot CLI#

A month ago, I received an invitation to use the GitHub Copilot CLI, which was still in technical preview at the time. It uses GPT to help us translate natural language into shell commands.

image

As shown in the demo GIF above, all we need to do is type ?? <instruction>, and GPT will write the desired command for us.

Pretty cool.

So I installed it and saw in its documentation a section on how to set up aliases for ?? for easier use:

...We recommend you install the ??, git?, and gh? commands in your shell...To install them, run the following command:

eval "$(github-copilot-cli alias -- "$0")"

Alright.

I was about to do that, but I suddenly wanted to make sure that ?? was a safe alias. So I typed ?? and hit enter:

➜ ~ ??

Go is a tool for managing Go source code.

Usage:

	go <command> [arguments]
...

Wait a minute....

Why does the ?? command link to go?

Searching and Asking#

So I asked in a Discord group:

image

Unfortunately, no one knew the answer.

Could it be that I misconfigured it in my .zshrc file? I checked for a while, and the answer was no. My configuration looked fine.

Next, I searched in the Golang Repo, but I couldn't find any content related to the ?? alias. There were no relevant issues either.

Then, I tried Googling it. But describing the problem became difficult. It seemed like even the keyword query of "???" couldn't be prioritized by the search engine. The search results were almost irrelevant.

image

It seemed like I was the first person on the entire internet to encounter this problem!

...

I gave up. I entered eval "$(github-copilot-cli alias -- "$0")" to set my ?? alias to github-copilot-cli, and everything looked fine as long as we ignored the weird part. The only thing that was still not perfect was that which ?? still gave me the location of the go binary because the function command initialization only runs at the start of each session. It was even more confusing.

image

More People Join the Mystery#

In the following month, many other people gained access to GitHub Copilot as well. Some of them encountered the same issue as me.

image image

I was glad that at least I wasn't alone.

The Answer is Finally Found#

Finally, today (one month later), a member of the GitHub Next team solved this case:

image

The ?? command expands to any two-character binary entry in the current working directory.

What does that mean?

He did point out the mechanism in general, but made a mistake—the ?? matches file names and directories, not binary files. To clarify, it means that when we use ??, we are looking for file names or directory names in the current folder that consist of exactly two characters.

No matter how many ? we input, the same rule applies!

image

In the example above, echo ?????? lists all possible directory or file names with a length of 6 characters; cd ????? takes us to the only directory with a length of 5 characters.

So, in our example, the ?? in the home directory resolves to the only directory with a length of 2 characters, go.

  • ?? -> go

If we are in another directory where there is no go directory, it won't work:

image

Wait... There's Another Question#

Didn't we say "file names or directory names"? Why does it bring up the go binary instead of entering the go directory?

That's right! I know, right? The expected behavior should be to enter the go directory (for bash, <dirname> is equivalent to cd <dirname>).

This is because the resolution of global binary file locations takes precedence over local file names or directories. For example:

image

Here, we create a file named go, and then when we type the go command, it doesn't execute the local go file, but the global go binary file. We need to explicitly input the relative path of the local file to execute it:

image

For directories, it has a similar behavior, but directories allow us to cd without using the explicit cd command.

So, if there is a file or directory named go in the current directory, and we input ??, it will expand to this go file name or directory name, and then try to execute it.

We can achieve the same effect with npm:

image

Just make sure that each word in the script has the same length, and the first letter of each word is in alphabetical order.

Well, I hope you enjoyed this April Fool's article. Now, change the "wow" script to rm -rf / and send it to your best friend, telling them to execute ???. Have fun! (Just kidding! Please don't do that!)

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.