0

I have a script to copy the files from one location to another where i am passing the first location as parameter to the script

#!/bin/bash
locatn=$1
echo $locatn
cp -r  /locatn/ /ws/priyapan-rcd/workspace/automation/

but when i run this code this throws error as cp: cannot stat `locatn': No such file or directory what could be the issue

5
  • there is no directory you should check your folder Commented Apr 14, 2016 at 6:49
  • you are referring locatn in the root directory, use this to refer in the current directory like this: cp -r ./locatn/ /ws/priyapan-rcd/workspace/automation/ , note the dot which has been added Commented Apr 14, 2016 at 7:04
  • It should be cp -r ${locatn} /ws/priyapan-rcd/workspace/automation/ no? Commented Apr 14, 2016 at 8:08
  • actually i am passing the location here as an argument to the script.the location variable has value /auto/ipcbu-build/Published/TPL_LIBRARIES/ Commented Apr 14, 2016 at 9:21
  • @PatrickTrentin yes this worked..thank u Commented Apr 14, 2016 at 9:31

1 Answer 1

3

Formatting looks a bit weird but as @Patick Trentin said you simply forgot a $ making your script always copy the files to the same location ignoring the given parameter.

#!/bin/bash
locatn=$1
echo $locate

cp -r  /${locatn}/ /ws/priyapan-rcd/workspace/automation/
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.