does << (input redirection in append mode ) works only for newline?
while reading about file creation in linux I got :
Another way to create a file at the terminal is
cat > <filename> << EOF
. A new file is created and you can type the required input. To exit, enter EOF at the beginning of a line.
so I tried this on my shell prompt
$ cat > test1.txt <<ABC
> This is just a test file.
> ABC
$ cat test1.txt
This is just a test file.
here when I typed ABC
(it could be anything - just for matching pattern) .in the newline it worked(accepted as it would have done in case of ctrl
+ C
),but when I tried
$ cat >> test1.txt <<ABC
> just for a trial
> though ABC
> it didnt worked.
> ABC
$ cat test1.txt
This is just a test file.
just for a trial
though ABC
it didnt worked.
$
doing this , it only worked in the newline. Does it mean that <<
works for newline,
And what's going on inside cat> test1.txt <<ABC
exactly ??
The final 'EOF' (the LimitString) should not have any whitespace or other characters in front of the word, because it means that the LimitString (in your case ABC
) will not be recognized.1
1Adapted and revised from https://stackoverflow.com/a/2954835/2907484