سؤال

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?

هل كانت مفيدة؟

المحلول

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top