I used the following two commands to produce the same results:-[root@localhost ~]# grep line commentsThe line should start with a single quote to comment in VB scripting.Double slashes in the beginning of the line for single line comment in C.[root@localhost ~]#[root@localhost ~]# grep line <commentsThe line should start with a single quote to comment in VB scripting.Double slashes in the beginning of the line for single line comment in C.[root@localhost ~]#Could any please explain to me any pros/cons if any of these 2 approaches over each other.
When should I use input redirection?
io redirection
From the man grep page (on Debian):DESCRIPTION   grep  searches the named input FILEs (or standard input if no files are   named, or if a single hyphen-minus (-) is given as file name) for lines   containing  a  match to the given PATTERN.  By default, grep prints the   matching lines.In the first case, grep opens the file, in the second the shell opens the file and assigns it to the standard input of grep, and grep not being passed any file name argument assumes it needs to grep its standard input.Pros of 1:grep can grep more than one file.grep can display the file name where each occurrence of line is foundPros of 2:If the file can't be opened, the shell returns an error which will include more relevant information (like line number in the script) and in a more consistent way (if you let the shell open files for other commands as well) than when grep opens it. And if the file can't be opened, grep is not even called (which for some commands, maybe not grep can make a big difference).in grep x < in > out, if in can't be open, out won't be created or truncated.There's no problem with some files with unusual names (like - or file names starting with -).cosmetic: you can put <file anywhere on the command-line to show the command flow more naturally like <in grep x >out if you prefer.