user1065734
user1065734

Reputation:

cat is not writing to a file?

i want to write to a file by cat command.

cat $variable >t.h

while it is not writing to the file. The file is empty anyway. why is cat not writing to the file?

Upvotes: 2

Views: 7364

Answers (1)

Alex
Alex

Reputation: 11090

cat itself does not write to file, only to stdout. The shell redirect > does the writing.

The problem with your statement is that cat takes list of file names as parameter, so cat $variable will attempt to print the contents of a file whose name is stored in $variable which most likely doesn't exist.

To write the contents of the variable to a file, use echo $variable >t.h

Upvotes: 10

Related Questions