1

Recently, I opened terminal and started typing everything i can, after which i accidentally put " and something like python shell was initialised:

muhammadrasul@AMR:~/Desktop$ lksdflaflakd;kfa;lk"
> a
> s
> 
> fd
> sfs
> fs
>

Then I realised that it works just for " as well. So, what that environment actually is and why does it ignore everything before that "?

ilkkachu
  • 133,243
  • 15
  • 236
  • 397

1 Answers1

3

" starts a string. The string lasts until the next " (except that \" put a " in the string and doesn't end the string). The string can contain newlines. So after entering a single ", the shell keeps reading input, because the string is unfinished.

When you terminate the string with another ", the shell will start executing the command. That's when it will complain that each of the commands is not found.

The > prompt is the shell's way to say that it's expecting more input. You can customize it through the variable PS2, which is analogous to PS1, but for continuation lines.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
  • so, if it takes a string, and if there is no such command like in the given string, it will say command not found, but otherwise will it execute that command? – Michael Adams Jul 19 '20 at 17:09
  • @Muhammadrasul Yes, if you have a command that contains a newline character (which is possible, but extremely unusual), and you type that command, it will execute that command. – Gilles 'SO- stop being evil' Jul 19 '20 at 17:10
  • huge thanks, I've learnt something useful! – Michael Adams Jul 19 '20 at 17:12
  • and `'` woks the same as `"`, almost like in python – Michael Adams Jul 19 '20 at 17:14
  • @Muhammadrasul In the shell, `'` works almost the same as `"`. The difference is that between `'`, no character is special, even `\ `. So you can't have a `'` inside `'…'` at all. You have to write `echo 'D'\''oh'` to get `D'oh` (or of course write it some other way such as `echo D\'oh` or `echo "D'oh"`). – Gilles 'SO- stop being evil' Jul 19 '20 at 17:23