Shell 脚本输出到控制台和登录在同一行?

标签 shell unix solaris

我能不能把这两行shell脚本剪成一行。

我的两行代码回显相同的字符串,但一行进入控制台,另一行进入日志文件。

echo "Starting scriptr" `date '+%T'`  >> script.log 
echo "Starting script" `date '+%T'`

谢谢

最佳答案

使用tee:

echo "Starting scriptr" `date '+%T'` | tee script.log

为了附加到日志文件,请说tee -a


引用自man tee:

   tee - read from standard input and write to standard output and files

关于Shell 脚本输出到控制台和登录在同一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19570627/

相关文章:

c - 无论 fork() 多少次,父进程仅从其子进程接收到 SIGCHLD 一两次

c - 如何在运行时获取数据和bss地址空间(在Unix C程序中)

linux - ping + 如何最小化 ping 命令的时间

linux - 如何在链接时自动发现隐式依赖

使用密码@进行Git克隆

linux - 无法使用 awk 或 cat 重定向数据

java - 通过 ProcessBuilder 运行时 Shell 脚本挂起

linux - 如何删除 linux 中提到的几个文件夹以外的所有文件夹

bash - 在 solaris 上规范化路径名

mysql - bash 中的子 shell MySQL 查询