Append file to file in bash without cat Append file to file in bash without cat bash bash

Append file to file in bash without cat


This is an orthodox use of cat. The "useless use of cat" involves using cat to read the contents of a single file and pipe them to another program which could just as easily read directly from the file using input redirection. Here, cat is doing all the reading and writing; there isn't anything simpler you could replace it with, since bash does not provide a built-in that reads from standard input and writes to standard output.


# Redirecting Input 'from' file to Command Substitution as "echo" argument# "echo" stdout write 'to' fileecho "$(<from)" > to# Redirecting Input 'from' file to Command Substitution as "printf" argument# "printf" stdout write 'to' fileprintf "%s" "$(<from)" > to# Redirecting Input 'from' file to "sed" and stdout write 'to' filesed -n '/.*/p' <from > to

envsubst
In normal operation mode, standard input is copied to standard
output, with references to environment variables of the form ‘$VARIABLE’`
or ‘${VARIABLE}’ being replaced with the corresponding values.

# create file with name 'template'echo '$buf' > template# Redirecting Input 'from' file to Command Substitution # Assign to 'buf' variable and export # envsubst standard input from 'template' file copied 'to' fileexport buf="$(<from)" && envsubst < template > to 


you can do

while read linedo    echo $linedone < file1 >> file2