I meet the following code in a book and still not understand why. Anyone can help to explain it please?
[root@wd00070319 test]# ls
[root@wd00070319 test]# touch file1
[root@wd00070319 test]# ls
file1
[root@wd00070319 test]# ls > file2
[root@wd00070319 test]# ls
file1 file2
[root@wd00070319 test]# cat file2
file1
file2
[root@wd00070319 test]#
The lesson here is probably that a command like
ls > file2creates the output-file (file2) before actually executing thelscommand.This behavior is confirmed by the bash reference manual: