Android 解决 ./system/bin/test.sh: No such file or directory

When doing Android development, pre-prepare test.sh to system/bin/test.sh, execute this script on the serial port and the error will be as follows:

console:/ # ./system/bin/test.sh                                  
/system/bin/sh: ./system/bin/test.sh: No such file or directory
console:/system/bin # sh startsoftdetector.sh                                  
inaccessible or not found
test.sh[23]: syntax error: unexpected 'fi'

This file exists but prompts No such file or directory ,

sh script syntax is fine but prompts syntax error: unexpected 'fi' ,

Cat -v ./system/bin/test.sh Check the file and find that there is ^M at the end of each line, indicating a format problem.

cat -v explanation:
-v, --show-nonprinting use ^ and M- notation, except for LFD and TAB


it Related to line breaks, the line breaks in different operating systems and editors are different

This script was edited under Windows and then copied to the Linux server, so there was something wrong with the format.

Solution:

  • 1. Manually edit and delete the ^M at the end of each line.
  • 2. Use the dos2unix system/bin/test.sh command to modify the file format.

More reference for how to remove ^M How to remove ^M in Linux - CSDN Blog

Guess you like

Origin blog.csdn.net/weixin_44021334/article/details/133693885