tags:

views:

32

answers:

3

Sometimes when I type a command in bash, I mistakenly type in the \ character at the end, as it is close to the Enter key. Whenever I do this, I get a prompt on the next line, like this:

>_

The same output is produced when the ` character is used.

What exactly does this \ do to the command?

Are there other characters (besides \ and `) that give a similar output?

+4  A: 

the \ character allows you to break your command into multiple lines :

$ grep "hello" /tmp/file

is equivalent to :

$ grep "hello" \
> /tmp/file

the ' and " character allows you to define multiline strings, and the ` is a way to use the output of a command as an argument to another. $(command) does the same thing.

whenever you see

>

it means that the command syntax is not complete. Some shell constructs also needs to be terminated, like while, for, if ...

The displayed > can be configured with the PS2 environnement variable.

as requested, here is an example using ` : suppose i have a list of files into filelist.txt:

$ cat filelist.txt
a.c
a.h
Makefile
test.cfg
[...]

i want to know the number of lines in each of those files. the command would be wc -l a.c a.h Makefile [...]. to use the output of the cat filelist.txt as arguments to wc -l, i can use :

$ wc -l `
> cat filelist.txt
> `
BatchyX
can you give an example for the use of ` too?
Kedar Soparkar
One tip regarding \: if you write a command, then Ctrl-C, it won't show up in history. But if you put \, and hit enter, and then Ctrl-C, it will.
ustun
+1  A: 

It may be because you forgot to close the ` or ' or ".

Aif
+1  A: 

\ is the line continuation character. When at the end of a line, the next line is considered a continuation of the current line.

` is a backtick. Backticks come in pairs, and bash allows contained newlines in pretty much any of the quotes/brackets. You'll see similar (line continuation) behavior with " and ' as well as () and {}.

Laurence Gonsalves