bash 解决 $1: 歧义重定向

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17628867/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 23:56:58  来源:igfitidea点击:

solve $1: ambiguous redirect

bash

提问by John Smith

I'm using this script to backup an old private instance of postgresql to gmail periodically:

我正在使用此脚本定期将 postgresql 的旧私有实例备份到 gmail:

#!/bin/bash
/opt/local/lib/postgresql83/bin/pg_dump maxgests -U postgres | gzip --best -c >  && (/opt/local/bin/mutt -s `date "+%d-%m-%Y-%H:%M"` -a   < /dev/null)

As of late I'm getting this:

最近我得到了这个:

./postgres_to_gmail.sh: line 2: : ambiguous redirect

And the script no longer works. Mac OS X 10.6.8.

并且脚本不再有效。Mac OS X 10.6.8。

Can anytone tell what's wrong and how to fix it?

谁能告诉我出了什么问题以及如何解决?

First argument is a path, like /tmp/database.gz

第一个参数是一条路径,比如 /tmp/database.gz

Second argument is the email.

第二个参数是电子邮件。

回答by tripleee

$1is apparently empty.

$1显然是空的。

As a general guidance, you should put your variable interpolations in double quotes, nearly always.

作为一般指导,您应该将变量插值放在双引号中,几乎总是如此。

回答by Zoltán Haindrich

the caller doesn't set the arguments ($1 $2) you should check the crontab or the program which calls is periodically more

调用者没有设置参数 ($1 $2) 你应该检查 crontab 或定期调用的程序

$ echo > 
bash: : ambiguous redirect