1

When i am defining array with the required values it's throwing below error

db_backup_daily.sh: 103: /home/user/Desktop/db_backup_daily.sh: Syntax error: "(" unexpected (expecting "fi")

The code which I have provided is getting executed in online shell editor but the same thing when I am trying to execute from my terminal it throwing error

#!/bin/sh
year=$(date +"%Y")
month=$(date +"%B")
day=$(date +"%d")
db_backup=/home/user/Documents/db_backup
YEAR_DIR=/home/user/Documents/db_backup/$year
MONTH_DIR=/home/user/Documents/db_backup/$year/$month
DAY_DIR=/home/user/Documents/db_backup/$year/$month/$day

FILE_NAME_ARRAY=( USER_TABLE_FILE PMT_TABLE_FILE FBA_PO_TABLE_FILE VENDOR_SUPPLIER_TABLE_FILE )

LOG_FILE_NAME_ARRAY=(USER_TABLE_LOG_FILE PMT_TABLE_LOG_FILE FBA_PO_TABLE_LOG_FILE VENDOR_SUPPLIER_TABLE_LOG_FILE)

TABLES_NEED_To_BACKUP=(Add_task checklist_task_management)

echo 'code executed successfully'

above code should get executed from the terminal

  • Possible duplicate of [Difference between sh and bash](https://stackoverflow.com/questions/5725296/difference-between-sh-and-bash) – oguz ismail Oct 15 '19 at 05:56

1 Answers1

0

#!/bin/sh means this script is meant to be run on the system's default POSIX shell, which is not always a link to bash/ksh, thus not guaranteed to support arrays. You need to change it to:

#!/bin/bash
oguz ismail
  • 1
  • 16
  • 47
  • 69