0

I am writing a bash script to copy some config files. I run the file using sudo bash configure.sh.

#!/bin/bash
cp config/ocr_pattern /usr/share/tesseract-ocr/tessdata/ocr_pattern
cp config/ocr_config /usr/share/tesseract-ocr/tessdata/tessconfigs/ocr_config

However when I view the changes made, ocr_config is copied correctly but ocr_pattern is copied with ocr_pattern? as the filename instead of ocr_pattern. There is an additional character ? behind in the filename for ocr_pattern. What is the issue here?

cat -A

#!/bin/bash^M
cp config/ocr_pattern /usr/share/tesseract-ocr/tessdata/ocr_pattern^M
cp config/ocr_config /usr/share/tesseract-ocr/tessdata/tessconfigs/ocr_config
6
  • Do you have three periods in your code? If so, you shouldn't Commented Oct 3, 2016 at 4:09
  • I don't understand your question - perhaps you could clarify it a bit Commented Oct 3, 2016 at 4:12
  • 1
    You may have a stray trailing character after file1 in your script. Commented Oct 3, 2016 at 4:16
  • 1
    Whats the output of cat -A configure.sh? Commented Oct 3, 2016 at 4:27
  • 1
    Your file may have DOS \r\n line endings. Check with cat -v. Commented Oct 3, 2016 at 4:27

1 Answer 1

2

As shown by the output of cat -A, you have carriage return (\r) at the end of some lines causing the mentioned issues.

Remove those:

sed -i 's/\r$//' configure.sh

or just use dos2unix:

dos2unix configure.sh
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.