piping the output to another command
The diff command works only if it has been provided with 2 files. Is it possible to replace one file with the output of another comma开发者_Python百科nd? The second command mentioned below does not work.
$ mysqldump -ushantanu -pPassWord test tbl --skip-extended-insert > to_backup.sql
$ diff `mysqldump -uroot -pPassWord test some_other_tbl --skip-extended-insert` to_backup.sql
-bash: /usr/bin/diff: Argument list too long
In bash you can use process substitution.
diff <(mysqldump ...) to_backup.sql
You can pipe one file from stdin
$ mysqldump -uroot -pPassWord test some_other_tbl --skip-extended-insert | diff to_backup.sql -
You can use -
as a special file name to represent standard input:
$ echo foo > bar
$ echo foo > baz
$ cat bar | diff - baz
or
$ mysqldump -uroot -pPassWord test some_other_tbl --skip-extended-insert | diff - to_backup.sql
精彩评论