bash cat 没有写入文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9435245/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
cat is not writing to a file?
提问by Alex
i want to write to a file by cat command.
我想通过 cat 命令写入文件。
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 不写入文件?
回答by Alex
catitself does not write to file, only to stdout. The shell redirect >does the writing.
cat本身不写入文件,只写入标准输出。shell 重定向>执行写入操作。
The problem with your statement is that cattakes list of file names as parameter, so cat $variablewill attempt to print the contents of a file whose name is stored in $variablewhich most likely doesn't exist.
您的语句的问题在于cat将文件名列表作为参数,因此cat $variable将尝试打印其名称$variable很可能不存在的文件的内容。
To write the contents of the variable to a file, use echo $variable >t.h
要将变量的内容写入文件,请使用 echo $variable >t.h

