我编写了一个 bash 文件,在其中使用 read 命令从文件中读取数据。

如果文件不存在,我想将错误保存到文本文件中。我试过了:

read myVariable < myFile  2> errorFile.txt

它不起作用,许多其他努力都失败了,例如:
myVar=`read myVariable < myFile`

最佳答案

在告诉 bash 从不存在的文件中读取之前,您需要先重定向 STDERR

这对你有用:

$ read myVariable 2> errorFile < myFile

或者
$ 2> errorFile.txt read myVariable < myFile

关于linux - 如何在 shell 脚本中保存 "read "错误输出?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9273958/

10-14 19:46
查看更多