- #1
shivajikobardan
- 674
- 54
- TL;DR Summary
- Small confusion about redirection in Linux
https://linux-training.be/funhtml/ch18.html
But later it says how it affects output erasing file case.
So can you explain how
My estimate
1) > is ignored
2) Number of arguments are count. There are 2 arguments "It is cold today!" and winter.txt
3) then what? i don't know.
Note that the bash shell effectively removes the redirection from the command line before argument 0 is executed. This means that in the case of this command:
Code:
echo hello > greetings.txt
I feel it's telling before counting the number of arguments, redirection operator is ignored.the shell only counts two arguments (echo = argument 0, hello = argument 1). The redirection is removed before the argument counting takes place.
But later it says how it affects output erasing file case.
While scanning the line, the shell will see the > sign and will clear the file! Since this happens before resolving argument 0, this means that even when the command fails, the file will have been cleared!
Code:
[paul@RHELv4u3 ~]$ cat winter.txt
It is cold today!
[paul@RHELv4u3 ~]$ zcho It is cold today! > winter.txt
-bash: zcho: command not found
[paul@RHELv4u3 ~]$ cat winter.txt
[paul@RHELv4u3 ~]$
So can you explain how
Code:
zcho It is cold today! > winter.txt command processes internally?
My estimate
1) > is ignored
2) Number of arguments are count. There are 2 arguments "It is cold today!" and winter.txt
3) then what? i don't know.