This one's driving me NUTS. Any help appreciated!

  • I've confirmed that the binary $MYSQLDUMP (within the script) has a valid full path
  • The command is complete (confirmed via echo)
  • $NOW is set early on in the script, and not here...so the time isn't changing on us or anything
  • This is not being run via cron
  • The user executing the script via command line, also has access/permissions to the actual directory
  • Tried dos2unix to ensure no weird characters. I'm on a Mac, but hey...why not
  • Attempted to escape the > like \>, which instead produces a mysqldump: Couldn't find table: ">" error

This one's driving me crazy. Not sure what I'm missing here? We're just directing output, and I feel like it's something ridiculously obvious I'm overlooking.


Added some more tests to debug and assist here.

vrb "whoami $(whoami)"
vrb "ls -ld \"$BACKUP_DIR/\" $(ls -ld \"$BACKUP_DIR/\")"
vrb "absolute path of user's home dir: $(cd ~/; pwd)"
vrb "absolute path of \$BACKUP_DIR: $(cd $BACKUP_DIR/; pwd)"


20160713T210808Z: $BACKUP_DIR: ~/www/__MYSQL/backup
20160713T210808Z: whoami william
ls: "~/www/__MYSQL/backup/": No such file or directory
20160713T210808Z: ls -ld "~/www/__MYSQL/backup/" 
20160713T210808Z: absolute path of user's home dir: /Users/william
./mygration.sh: line 383: cd: ~/www/__MYSQL/backup/: No such file or directory
20160713T210808Z: absolute path of $BACKUP_DIR: >> ERROR: 1

vrb is just another function that processes verbose output in the script, so don't be alarmed by that. It's only for outputting the debugged info.

If I manually list the contents in the same terminal to ~/www/__MYSQL/backup/, I can see the following:

$ ls -la ~/www/__MYSQL/backup/
total 0
drwxr-xr-x  2 william  staff   68 Jul 13 20:55 .
drwxr-xr-x  6 william  staff  204 Jul 13 20:55 ..

It's weird. Almost like Bash doesn't have access, but my regular user (the one running the bash script in the first place) does.


echo $(whoami);
echo ~;


  • I still don't see ls -ld ~/www/__MYSQL/backup/ which could perhaps give us clues as the situation is getting weirder. Jul 14, 2016 at 4:27

1 Answer 1


The problem is that you've put the tilde inside double quotes. When you do this, it is not expanded to the path of your home directory.


MacBook-Pro:~ error$ cat x.sh
echo ~
echo "~"
ls ~
ls "~"
MacBook-Pro:~ error$ ./x.sh
Calibre Library Downloads   Music       bin
Desktop         Library     Pictures    synergy
Documents       Movies      Public      x.sh
ls: ~: No such file or directory
MacBook-Pro:~ error$ 

If you wish to continue using double quotes, use the $HOME variable instead of the tilde.

MacBook-Pro:~ error$ echo $HOME
MacBook-Pro:~ error$ echo "$HOME"
MacBook-Pro:~ error$ 
  • Well done Michael. Well done. I ended up doing an $(eval echo ${BACKUP_DIR}), which worked great. Curious if there are better ways, but that worked. Jul 14, 2016 at 21:35
  • Go back to wherever you originally defined $BACKUP_DIR and remove the double quotes. Jul 14, 2016 at 21:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.