0

I have a .bash_aliases file I've been using for a long time. Today I added some commands that are broken into multiple lines (using \).

Since doing that, I can't source the file to reload it. When I do it gets stuck. It just sits there, with a flashing cursor on a new line, and doesn't return me to the command prompt.

Initially doing the source command would return the following error (which I'd not had prior to adding the multi-line commands)

-bash: alias: date: not found
-bash: alias: +%Y-%m-%d-%H.%M.%S: not found

So I changed the line:

    /home/waiheke26/sites/www.waihekehoney.co.nz/backups/wp-files-$(date +%Y-%m-%d-%H.%M.%S).tar.gz \

to

    '/home/waiheke26/sites/www.waihekehoney.co.nz/backups/wp-files-$(date +%Y-%m-%d-%H.%M.%S).tar.gz' \

That stopped that error. But now when I run source ~/.bash_aliases it just sits with a flushing cursor.

UPDATE:

I added a missing " as noted by Spiff in the comments. But now I get these errors when doing a source on the file:

-bash: alias: backup: not found
-bash: alias: OK || echo Database: not found
-bash: alias: backup: not found
-bash: alias: failed: not found

I've gone through the file, and I can't see what the issue is.

QUESTION: What is causing this .bash_aliases file to not update when sourced?

Here's the file (domain name removed)


alias bashupdate="source ~/.bash_aliases";
alias aliases="cat ~/.bash_aliases";

alias wphome="cd /home/waiheke26/sites/www.waihekehoney.co.nz/public";

alias wpsyncfolder="cd /waiheke26/sites/www.waihekehoney.co.nz/backupsync";

alias wpsync="wphome && rsync -va --exclude 'cache' \
    --exclude 'wp-content/uploads' \
    --exclude 'wp-content/cache' \
    --exclude 'wp-content/uploads' \
    --exclude 'wp-content/backups' \
    --exclude 'wp-content/envato-backups' \
    /home/waiheke26/sites/www.waihekehoney.co.nz/public/ \
    /home/waiheke26/sites/www.waihekehoney.co.nz/backupsync/public/ --delete";

alias wptar="wpsyncfolder && tar -zcf \
    '/home/waiheke26/sites/www.waihekehoney.co.nz/backups/wp-files-$(date +%Y-%m-%d-%H.%M.%S).tar.gz' \
    . \
    && echo 'File backup OK' || echo 'File backup failed'";

alias wpbackup="dbbackup && wpsync && wptar && cleanbackups";

# alias wpbackup="wphome && tar --exclude='./wp-content/uploads' --exclude='./wp-content/cache' --exclude ='./cache' --exclude='./wp-content/backups' --exclude='./wp-snapshots' --exclude='./wp-content/envato-backups' -zcf /home/waiheke26/sites/www.waihekehoney.co.nz/backups/wp-files-$(date +%Y-%m-%d-%H.%M.%S).tar.gz . && echo "File backup OK" || echo "File backup failed"';
alias dbbackup="wphome && wp db export --add-drop-table && mv *.sql /home/waiheke26/sites/www.waihekehoney.co.nz/backups/ && echo "Database backup OK" || echo "Database backup failed"";

alias cleanbackups="find /home/waiheke26/sites/www.waihekehoney.co.nz/backups -mtime +7 -delete";
alias cleanbackups-test="find /home/waiheke26/sites/www.waihekehoney.co.nz/backups -mtime +7 -print";

alias wpdbbackup="wpbackup && dbbackup && cleanbackups";
7
  • 1
    You never closed the doublequotes on the definition of wpsync
    – Spiff
    Commented Oct 18, 2019 at 22:24
  • @spiff thanks for that. I was going blind to my code. Looked over it so many times, and didn't see that.
    – inspirednz
    Commented Oct 18, 2019 at 23:34
  • 1
    Now look at your definition for dbbackup. You either need to escape the doublequotes around "Database backup okay" and "Database backup failed", or change them to single quotes.
    – Spiff
    Commented Oct 19, 2019 at 0:08
  • 1
    Generally, use single-quotes unless you need $-expressions to work. Also, realize that there's no way to tell open-quotes vs. close-quotes in most computer languages, because they all use straight ASCII quotes which don't have separate "open" vs. "close" forms. So there's no such thing as "nesting" double-quotes, because there is no way to communicate that you wanted a "nested open-quote" as opposed to a closing-quote.
    – Spiff
    Commented Oct 19, 2019 at 0:18
  • 1
    One last tip: Consider using an editor that supports syntax coloring for shell scripts. It helps make quoting problems more visible.
    – Spiff
    Commented Oct 19, 2019 at 0:19

1 Answer 1

0

The two issues were as follows:

  1. One of the alias definitions was missing it's closing double quotes. (as noted by Spiff in the comments).
  2. I had changed around some of the double and single quotes, whilst trying to fix the issue. This resulted in double quotes being nested within double quotes, which is what generated the errors noted in the UPDATE in the question. I needed to either escape those nested double-quotes, or change them the single quotes. (as noted by Spiff in the comments).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .