如何从 csh 脚本重定向 stdout 和 stderr
对于以下脚本
install.csh:
#!/bin/csh -f tar -zxf Python-3.1.1.tgz cd Python-3.1.1 ./configure make make install cd .. rm -rf Python-3.1.1
预期用途:
./install.csh |& tee install.log
如何更改脚本,以便仍然在控制台上获得 install.log 和输出,而不要求用户进行重定向?
For the following script
install.csh:
#!/bin/csh -f tar -zxf Python-3.1.1.tgz cd Python-3.1.1 ./configure make make install cd .. rm -rf Python-3.1.1
Intended use:
./install.csh |& tee install.log
How can I change the script so that I still get a install.log and the output on console without asking the user to do the redirecting?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一些简单的解决方案:
解决方案 1:
tee 想要独立记录的每一行,使用 tee 的
-a
开关来附加解决方案 2:添加第二个脚本。
例如,将当前的 install.csh 重命名为 install_commands,
然后添加一个新的 install.csh 脚本:
Some simple solutions:
Solution 1:
tee every line you want to log independently, make use of
-a
switch of tee to appendSolution 2: Add a second script.
For example, rename current install.csh to install_commands,
then add a new install.csh script:
你好,
我强烈建议从 csh 转向 bash 或 zsh 之类的东西。
csh 中无法进行 stdio 操作。阅读“csh 编程被认为有害”。关于这个主题的一篇优雅的论文。
抱歉,这不是一个直接的答案,但您会发现,您坚持使用的时间越长,您就会不断地撞上 csh 的限制。
bash 中已经提供了许多 csh 语法,因此您的学习曲线不会太陡。
这是对用 bash 编写的相同内容的快速建议。但它并不优雅。
我添加了更多的检查和报告,这样如果前面的步骤出现问题,日志文件将只包含直到发现错误为止,而不是一堆来自后续阶段的无法完成的非常无用的错误消息反正。
干杯,
G'day,
I highly recommend moving away from csh towards something like bash or zsh.
stdio manipulation is not possible in csh. Have a read of "csh programming considered harmful". An elegant treatise on this topic.
Sorry it's not a direct answer but you'll find that you'll keep banging your head against the constraints of csh the longer you stick with it.
A lot of csh syntax is already available in bash so your learning curve won't be too steep.
Here's a quick suggestion for the same thing written in bash. It's not elegant though.
I've added a bit more checking and reporting so that if there's a problem in an earlier step the log file will just contain up until the error was uncovered rather than a stack of pretty useless error messages from the later phases that wouldn't complete anyway.
cheers,
您可以在子 shell 中运行它并重定向其所有输出。不记得这在 csh 中是否有效,我已经很久很久没有使用它了。
You can run it in a subshell and redirect all the output of that. Don't remember if this works in csh, it has been a long, long time since I used that.