0

I want to use cp command using two variable but doesn't work

#!/bin/sh

PATH="/home/smvm/Dropbox/ssd-tech/SoftSwitch"


SRCPATH=${PATH}/lib/SIPLib/*.a
DESTPATH=${PATH}/include

cp "$SRCPATH" "$DESTPATH"

Following Error Occurs

copyPaste.sh: 9: copyPaste.sh: cp: not found
smamran
  • 741
  • 2
  • 14
  • 20

1 Answers1

6

PATH is a special variable used to locate executables. Change PATH in your script with another variable (preferably a lower-case one) and your problem will be solved:

#!/bin/sh

dir="/home/smvm/Dropbox/ssd-tech/SoftSwitch"


srcfiles=${dir}/lib/SIPLib/*.a
destdir=${dir}/include

cp $srcfiles "$destdir"

As a general advice - don't use ALL UPPERCASE VARIABLES in your bash scripts, in order to avoid potential conflicts with reserved environment variables.

Leon
  • 31,443
  • 4
  • 72
  • 97
  • Correct, `$srcfiles` must be unquoted for the glob expansion to work. I updated the answer. – Leon Nov 17 '16 at 12:23
  • Please edit "$destdir" as $destdir – smamran Nov 17 '16 at 12:27
  • @S.M.AMRAN No, `$destdir` must remain quoted, so that it is not expanded and always remains as a single argument – Leon Nov 17 '16 at 12:28
  • 2
    Note that putting a glob in a variable isn't good practice. Since it requires the parameter remain unquoted, `srcfiles` couldn't contain a path containing whitespace, e.g., `srcfiles="/home/me/My Libraries/SIPLib/*.a"`. Use the pattern to populate an array instead. `srcfiles=( "$dir"/lib/SIPLib/*.a )`, then `cp "${srcfiles[@]}" "$destdir"`. – chepner Nov 17 '16 at 12:46