When to use echo in The Linux Command Line

As the title says…

ls -lah > allFiles.txt
// creates a file called allFiles.txt and writes the list of all files in the current directory to it

but if I use grep and want to write the result to a file I have to use “echo”…

echo grep root /etc/passw > root.txt
// creates a file called root.txt and writes the search result in it

Why “ls” doesn’t require the “echo” command?

Which lecture are you referring to? echo writes its arguments to standard output so the second command wouldn’t do what the comment suggests but create a file with “grep root /etc/passw” in it.

Sorry, I had it wrong in my mind. The grep example doesn’t require “echo”, otherwise it will write just the command to the file, as SAM mentioned.

It’s in lecture “The Linux Command Line (65m)”

I meant it in this case:

echo DB_USER=mosh >> .bashrc

Why echo is required here?

Is it because the redirection operators (> and >>) require a value to be returned in order to be used?

With >> .bashrc you say that you want to append the contents of standard output to the file .bashrc. echo puts that content into standard output - in this case DB_USER=mosh.