I'm writting a quick script for transfering a webpage from a remote server to my local machine. The problem is that I get a ": No such file or directory" error for my local folder. But if I don't use variable and just type the command in the script, it works. It works even if I echo the command and then just run it in the terminal. Im thankfull for any ideas!
This is the script:
#!/bin/bash
WEBPAGE_NAME="wikiwebpageb"
USERNAME="banana"
IP="192.168.0.12"
PORT_NUMBER="4561"
WEB_BACKUP_DIR="~/backups/wiki_backups/webpage/"
LOCAL_WEB_BACKUP_DIR="~/backups/wiki_backups/webpage/"
LOGFILE=~/backups/backups.log
scp -P $PORT_NUMBER ${USERNAME}@${IP}:${WEB_BACKUP_DIR}1_${WEBPAGE_NAME}.tgz ${LOCAL_WEB_BACKUP_DIR}1_${WEBPAGE_NAME}.tgz 2>> $LOGFILE
~
does not expand inside a variable. That's OK for WEB_BACKUP_DIR because you want the remote system to expand the tilde. But not so good for the local variable, as you've noticed. Quick fix, use$HOME
instead of~