8

When exploring some of the flags associated with mv in zsh terminal, I encountered the following prompt: overwrite untitled folder 2/test.txt? (y/n [n])

My question is what is the second n in brackets seeking to ask or suggest? Why is the prompt not just y/n and why is it y/n [n]?

What does this mean? Can someone please explain the significance of [n]?

3
  • 8
    Something similar you might also encounter, is choice prompt where the capital letter denotes a default: e.g. (Y/n)
    – Emma
    Commented Oct 31, 2022 at 1:23
  • 3
    It means if you press ENTER without typing y or n it assumes you meant n
    – slebetman
    Commented Nov 1, 2022 at 6:35
  • @T.Kent You may wish to edit to change “zsh terminal” to “zsh shell” and the title “terminal” to “zsh shell” as it introduces confusion about your core question. Commented Nov 2, 2022 at 9:39

2 Answers 2

20

If you just hit enter, it assumes the part in brackets. In your case, the default is “n”.

0
15

zsh is not a terminal, it's just a shell, a programming language with an interactive mode specialised in running other commands.

Terminal emulators such as xterm, gnome-terminal are configured to run your login shell¹ as the initial application that displays there.

From the shell prompt, you typically run other commands such as ls, vi, etc which do output to the terminal as well.

It's not because the title of the terminal window says xterm or zsh, that what you see in it is output by xterm or zsh itself. It is displayed by whatever applications wrote it to the pseudo-terminal device associated with the terminal window.

Specifically, overwrite untitled folder 2/test.txt? (y/n [n]) is not a message that the zsh shell outputs, zsh doesn't overwrite "folder"s. zsh is a Unix shell and "folder" is not even Unix terminology. You have "directories" in Unix, not "folders"².

Having said that, using y/n [n] is a very common idiom when prompting users on a terminal. The general form is:

Question? acceptable-answers [default]

Or variations such as openSUSE zypper's:

Continue? [y/n/v/...? shows all options] (y):

Which asks a question, optionally lists what answers are acceptable and says what the default answer is when you answer nothing.

So, here, it's a yes/no answer with the default answer being "no".

That form is useful when asking a bunch of questions to configure some software, for instance, so that the user can keep pressing enter unless they want to modify a default setting.

Other common forms besides full blown TUIs, are to list the settings as:

1. setting1: current-value
2. setting2: value2
3. ...

What setting would you like to change?

And let the user choose what they want to change (the next prompt for the selected setting can still use the question? x/y/z [x] style).


¹ well the shell referenced in the $SHELL environment which happens to be initialised from your login shell upon login

² We do see that Microsoft terminology leaking to Unix lately though, especially in desktop environments.

1
  • Note that untitled folder 2 appears to be a failed-to-be-quoted directory name by itself. Commented Nov 1, 2022 at 16:42

You must log in to answer this question.

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