When I enter single quote
' in terminal it goes to some other mode, and commands don't execute. What is this mode and when do we use it?
root@sai:~# ' > ls > ' ls : command not found root@sai:~#
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
Effectively, the shell asks for a complete command/expression, and for that reason is displaying the
PS2 prompt string.
When executing interactively, bash displays the primary prompt PS1 when it is ready to read a command, and the secondary prompt PS2 when it needs more input to complete a command.
And a little before that:
PS2 The value of this parameter is expanded as with PS1 and used as the secondary prompt string. The default is ``> ''.
Thus, as you may guess from reading the documentation, shells have multiple prompts with different purposes. The
PS1 prompt is your
root@sai:~# string, which shows up normally when you enter commands.
> is the
PS2 prompt. There's others, too:
select command block and
PS4 for debugging with
set -x command. In this case we're more interested in
There are many ways in which shell may show the
PS2 prompt (and where completing a command on a new line might be necessary). The same prompt is used when you perform
here-doc redirection (where a command is considered complete when you see the terminating string, in this example,
$ cat <<EOF > line one > line two > EOF line one line two
Very often continuation of a lengthy command can be done by adding
\ and immediate(!) newline, which will cause the same prompt to appear:
$ echo Hello\ > World HelloWorld $ echo 'Hello\ > World' Hello\ World
When pipes, logic operators, or special keywords appear on command-line before newline, the command also is considered incomplete until all final statements are entered:
$ echo Hello World | > wc -l 1 $ echo Hello World && > echo "!" Hello World ! $ for i in $(seq 1 3); do > echo "$i" > done 1 2 3 $ if [ -f /etc/passwd ] > then > echo "YES" > fi YES
In your particular case, a single quote implies literal interpretation of what is between the single quotes. Thus, as Zanna pointed out, you are entering a command that consists of newline+
ls+newline. Such an executable filename cannot be found (and typically command filenames should consist of only alphanumeric characters, plus underscores, dashes, and dots). Although it is indeed possible to have filenames that contain special characters in them, it is always avoided.
NOTE: such behavior as shown in your example is specific to Bourne-like shells, including
dash (on Ubuntu it is symlinked to
csh and its derivatives do not behave in such way:
$ tcsh eagle:~> ' Unmatched '. eagle:~> csh % ' Unmatched '. %
However, in interactive mode,
csh will still raise
? as prompt2 when more input is required:
$ csh % foreach n ( 1 2 3 ) ? echo $n ? end 1 2 3
The shell is just waiting for the closing quote. When you enter it, it will do exactly what it usually does, and attempt to execute the command entered.
Quotes cause the shell not to interpret special characters, meaning that expansions are not performed. Single quotes suppress all interpretation of special characters completely. Normally a newline separates commands, but here you have included the newlines as part of the command by quoting them.
Since there is no such command as
<newline>ls<newline>, it is not found.