将输出重定向到命令结果给定的文件名 [英] Redirect output to filename given by result of command

查看:36
本文介绍了将输出重定向到命令结果给定的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一种文件格式,希望将数据库备份保存为给定的格式:

Suppose I have a file format I want to save database backups to given as such:

echo "~/backups/$(date +'%Y-%m-%d_%H-%M-%S').sql"

现在如何将这个结果指定为文件名,以便在Shell中输出?

Now how can I specify this result as a filename for output in shell?

mysqldump my_db > ....?

顺便说一句: shell将嵌套的echo命令的结果解释为可执行的命令/文件.所以   似乎是:

By the way: shell interprets the result of a nested echo command as an executable command/file. So    It would seem that:

 mysqldump my_db > $(echo "something")

不起作用.相反,shell查找名为 something 的文件并尝试执行该文件?

does NOT work. Instead, shell looks for a file called something and tries executing it?

推荐答案

无需使用嵌套回显.您可以避免它:

There is no need to use nested echo. You can avoid it:

mysqldump my_db > ~/backups/$(date +'%Y-%m-%d_%H-%M-%S').sql

这篇关于将输出重定向到命令结果给定的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆