Piping
yes
is a command that repeatedly outputs a string (defaults to "y") until killed. See man yes
cat
is a command that outputs to STDOUT everything it receives on STDIN or the concatenation of all the files listed as parameters. See man cat
The pipe (|
) redirects the STDOUT from the previous command to the STDIN of the next command.
Therefore, piping to cat
is a waste of CPU cycles.
Variable assignment
Variable assignment allows you to temporarily store a string in memory.
Example:
$ test="this is a string!"
$ echo $test
this is a string!
If you want to store the result of a command in a variable, you would need to use a subshell.
Example:
$ echo "file contents :)" > test.file
$ test="$(cat test.file)"
$ echo $test
file contents :)
Reference
For detailed usage of bash, see https://www.gnu.org/software/bash/manual/bash.html
cat
? Is that whyyes | echo
does nothing? – William Nov 18 '15 at 23:08yes
, infinite amount of data. In the case ofyes | echo
, the pipeline terminates because the commandecho
does not read its input: it simply exits after printing a single newline. The writing process,yes
, will then receive a SIGPIPE signal as it tries to write, and will exit. – dhag Nov 19 '15 at 01:29