7

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

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

As of late I'm getting this:

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

And the script no longer works. 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

Second argument is the email.

John Smith
  • 1,572
  • 2
  • 16
  • 29

2 Answers2

14

$1 is apparently empty.

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

tripleee
  • 158,107
  • 27
  • 234
  • 292
  • For detailed quoting guidance, see [When to wrap quotes around a variable](http://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-variable). – tripleee Jul 13 '16 at 07:22
1

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

$ echo > $1
bash: $1: ambiguous redirect
Zoltán Haindrich
  • 1,738
  • 11
  • 18