Reputation: 18337
I'm trying to make mysql database input from a file. But the db filename
will be coming from the variable filename= /file/path/name.sql
. But when input using <
it is showing ambiguous redirect
error.
My full script is:
filename= /var/backup/mydatabase.sql
echo $filename
mysql -uxxxx -pxxxx -hxxxx databasename < $filename
And the output is:
/var/backup/mydatabase.sql
./myscript.sh: line 3: $filename: ambiguous redirect
Please note followings:
filename
variable is needed for some reasonSo my question here is:
shell variables
for file input purpose?Upvotes: 0
Views: 950
Reputation: 161874
filename= /var/backup/mydatabase.sql
^
Spaces around =
are not allowed when you define a variable.
Please remove the space after =
.
./myscript.sh: line 3: $filename: ambiguous redirect
This error message tells your that $filename
may expand to multi-words.
Please double-quote "$filename"
.
Make sure that script file doesn't contain any invisible ctrl-chars at end of line.
Use command xxd myscript.sh
to check.
Upvotes: 3