Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

solve $1: ambiguous redirect [duplicate]

Tags:

bash

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.

like image 839
John Smith Avatar asked Jul 13 '13 09:07

John Smith


2 Answers

$1 is apparently empty.

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

like image 120
tripleee Avatar answered Nov 15 '22 23:11

tripleee


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
like image 22
Zoltán Haindrich Avatar answered Nov 15 '22 22:11

Zoltán Haindrich