当前位置:网站首页>Problem solving: interpreter error: no file or directory

Problem solving: interpreter error: no file or directory

2022-07-05 08:05:00 Car chezi

Execute a I wrote perl Script , Command line error :

/usr/bin/perl^M: Interpreter error : There is no file or directory

analysis :
UNIX and Linux Use “\n” Line break , and Windows use “\r\n”( No \n\r, Verified ).
It is speculated that the script file is windows Edited by . use sed The command puts \r Get rid of .

solve :
sed -i 's/\r$//' filename

Explain it. ,-i Express edit files in place, Modify the original text directly
s/a/b/ Express the a Replace with b
$ Express “ End position ”
So the above command means : If a line with \r ending , Just put \r Replace empty , That is to remove it .

Someone asked , Not in \r\n The end ?

Use standard sed, You will not see line breaks . This is because sed Read line by line , So in sed In pattern space , There is no newline at the end of the current line of text . let me put it another way ,sed Read data separated by newline , And the separator is not sed Part of what the script sees .

therefore ,\n As a separator , So at the end of each line is \r .


Reference material
How to use sed Detect end of line

原网站

版权声明
本文为[Car chezi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140546257726.html