0

I want to move 2 files from current directory to archive directory and rename the files while doing it with prefixing the date and changing the file extension. the script below it does work if i remove the move directory part of it. please see script and error message blow. the permission on the archive directory is 777 so is the files.

#!/bin/bash
  cdate=$(date +%Y-%m-%d)
  destdir=${/home/dcaceres/load/archive}
   for file in allcustomer.csv loadcustomer.csv; do
    mv "$file" "$destdir/$cdate"_"$file"".ARCHIVE"
  done 

    the error.
    ./archive_customer_load.sh: line 3: /home/dcaceres/load/archive: Is a directory

mv: cannot move 'allcustomer.csv' to '/2017-12-12_allcustomer.csv.ARCHIVE': Permission denied

mv: cannot move 'loadcustomer.csv' to '/2017-12-12_loadcustomer.csv.ARCHIVE': Permission denied
BenRoob
  • 1,662
  • 5
  • 22
  • 24

1 Answers1

0

Changing the line below will do the work:

destdir=${/home/dcaceres/load/archive}

to:

destdir="/home/dcaceres/load/archive"

Explanation:

Curly brackets are needed when using variables, that too is not always necessary. It is useful in many cases, for example, concatenating a string to value of a variable, when using an array or when using parameter expansion.

Here in your case, we just need to assign the variable destdir with a string, so we can directly do it with quotes.

For more information: When do we need curly braces around shell variables?

PesaThe
  • 7,259
  • 1
  • 19
  • 43
Jithin Scaria
  • 1,271
  • 1
  • 15
  • 26