i wrote a multipart script that calls rsync a few years ago and it has always worked. After a year of no use and alot of debian apt-get updates, now the script stopped working.

Main2Network1.sh calls Main2Network2 there are parts 3 & 4 but the scripts Main2Network1.sh line 27 with:

 Main2Network1.sh: [[ not found 

Line 27 is

if [[ -z $VAR ]];

When i wrote the script the script the [[ ]] were necessary for the if then to work with just pressing the enter key i.e. https://stackoverflow.com/a/20201920/9383998

maybe someone can tell me if they see any recently deprecated syntax in my code around line 27 (thats where i get an error running script) thanks all


#renames files changed files on NETWORK to _day_mnth_yr_NETWORK1 then puts maincomp version of file on network.
#info=NAME1 lists just changed Files/Dirs, -b must preceed --suffix,
# this will change existing dup file on travel to date_TRAVEL replacing base file with network version
#SOURCE File Dups replace network and network copy renamed to _NETWORK1
echo "source MAIN dir?"
SO=$(echo ${SOURCE}/ | tr -d "[='=]")
echo "destination NETWORK dir?"
read DEST
DE=$(echo ${DEST}/ | tr -d "[='=]")
echo "exclude file?"
EX=$(echo ${EXCLUDE} | tr -d "[='=]")
echo "=========================================="
echo "Exclude is $EXCLUDE"
echo "rsync destination is $DE"
echo "rsync Source is $SO"
echo "rsync exclude is $EX"
echo "=========================================="
mkdir "${0%/*}"/`eval date +"%d"_%m_%Y`log/
LOG=$(cd `dirname $0` && pwd)/`eval date +"%d"_%m_%Y`log/
# ~/ issue
rsync -aEv --info=NAME1 -c -n --numeric-ids -z -b --suffix=_%d%m%Y_%H%M_NETWORK1 --exclude-from=${EX} ${SO} ${DE} > $LOG/Main2NetworkStep1LOG.txt

echo 'check output if acceptable continue?'
read VAR
if [[ -z $VAR ]];
     echo "backing up Main To Network"
     echo ==================================================
     source /`dirname $0`/Main2Network2.sh
     echo 'Main System backed up'
    echo "Ok"


DAY=`eval date +"%d"`
MONTH=`eval date +"%m"`
YEAR=`eval date +"%Y"`
echo 'beginning REAL Main to network backup'
echo ================================================================
rsync -aEv --info=NAME1 -c --numeric-ids -z -b --suffix=_${MONTH}_${DAY}_${YEAR}_NETWORK1 --exclude-from=${EX}  ${SO} ${DE} > ${LOG}/Main2NetworkRealBackupStep2Log.txt
echo 'all done Main to Network sync'
leafpad ${LOG}/Main2NetworkRealBackupStep2Log.txt
echo 'begin Network to Main backup process?'
echo ========================================
read VAR
if [[ -z $VAR ]];
     echo "Generating Network to Main Backup Dry Run Report"
     source /`dirname $0`/Main2Network3.sh
    echo "Ok"
  • 9
    Is the first character of Main2Network1.sh a blank, or is that a cut and paste artifact? – Mark Plotnick Feb 13 '19 at 1:34
  • Try to reduce your script to a minimal failing example, i.e. the smallest snippet of code that you can make fail. At the moment, it's full of extraneous irrelevant code. – Sparhawk Feb 13 '19 at 2:16
  • 4
    In the vast majority of cases this is because the script is run as sh Main2Network1.sh, which ignores the shebang line. – l0b0 Feb 13 '19 at 2:39
  • This script has a bunch of bad practices (esp. failure to double-quote variable references). I recommend running it through shellcheck.net. – Gordon Davisson Feb 13 '19 at 4:16
  • @l0b0 you are totally right....simple is usually most direct solution huh...still unsure why previous years sh and bash were acceptable to this script, but simple solution solves the bigger problem - TY – debdragon Feb 13 '19 at 15:02

The following works for me, returning true if "just enter" is hit, or any number of spaces, or a few tabs. Any alphanumeric, etc. returns false.

if [ -z $VAR ]
 ..... do your backup stuff here
  "ok, not backing up"

FWIW I'd change the prompt to make it more clear to "just hit enter to run the backup, any character(s) to exit"


Your problem is on the very first line of Main2Network1.sh:

#renames files changed files on NETWORK to _day_mnth_yr_NETWORK1 then puts maincomp version of file on network.

See that stray space at the start? That turns your shebang line into just another comment, so the kernel defaults to running your script with /bin/sh, which doesn't understand the [[ ]] construct.

Remove that space, and all should be well.

  • ugh - that makes total sense ... never caused an issue before - maybe a line spacing - will try - @Adrian – debdragon Feb 13 '19 at 14:13
  • yeah the space at the start didn't fix things - removed the space and still same result. @l0b0 was spot on that now sh and bash must not be used with bash scripts...bash scripts can now just be run by file name and location alone....ie dragon:~#/home/ftpd/networkbakup.sh – debdragon Feb 13 '19 at 15:04
  • @debdragon What does file Main2Network1.sh say? – Adrian Feb 13 '19 at 15:11

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