test.sh: line 3: $‘\r‘: command not found 或者 vim去掉^M字元
這兩種現象其實對應同一種問題:在windows下編輯的檔案放到linux上執行時會出現這個問題。
例如,有一個test.sh檔案,通過vim直接開啟時看到的是這樣的:
發現並沒有什麼問題。其實應該通過vim -b test.sh開啟,這樣看到的就是本來面目了。
vim -b test.sh
所以
方法一、把^M刪掉就可以了。按i進入編輯模式,刪除即可。
如果^M太多,可以使用查詢替換命令,vim開啟檔案然後
:%s/^M//g
注意這個^M不是看到的^M,而是要ctrl+V,ctrl+M敲出來。
方法二、修改檔案的格式:set ff=unix
擴充套件知識:
在DOS/Windows 的文字檔案在每一行末尾有一個 CR(回車)和 LF(換行),而 UNIX 文字只有一個換行,即win每行結尾為\r\n,而linux只有一個\n
如果win下的文件上傳到linux,每行的結尾就會出現一個^M,(^M是ctrl+v,ctrl+m)
所以要麼去除這個\r要麼修改檔案格式。
相關文章
- vim介面去掉^M符號符號
- shell指令碼執行錯誤 $‘\r‘:command not found指令碼
- 解決shell指令碼錯誤$’r’ command not found指令碼
- bug solved | zsh: command not found: mongo (Mac M1/M2 )GoMac
- -bash: id: command not found -bash: tty: command not found
- Command Line Tools
- 【node】command-line
- nodemon: command not found
- pip: command not found
- Command line is too long. Shorten command line for JooLunMallApiApplication or also for Spring Boot default configuration?APIAPPSpring Boot
- zsh:command not found: xxx
- mac mysql: command not foundMacMySql
- idea遇見Command line is too long. Shorten command line for Main or also for Application default configuration?IdeaAIAPP
- Azure Command Line (一)入門
- Linux:-bash: tree: command not foundLinux
- Linux:-bash: unzip: command not foundLinux
- Mac -bash: mysql: command not foundMacMySql
- change ^M to new line
- Error running ‘Application’Command line is too longErrorAPP
- sudo: apt-get: command not foundapt-get
- centos 7 -bash: mysql: command not foundCentOSMySql
- 【Linux】git note -v command not foundLinuxGit
- Spring Boot Intellij 執行應用的時候 Command line is too long. Shorten command line for 錯誤Spring BootIntelliJ
- Install VMware Tools in CentOS 7 command line modeCentOS
- MySQL 5.7 Command Line Client 閃屏退出MySqlclient
- IDEA命令列縮短器助你解決此問題:Command line is too long. Shorten command line...Idea命令列
- 【linux報錯】-bash: xhost: command not foundLinux
- bash: lspci: command not found解決方法
- 從 egg-bin 聊到 command line interface Tool
- -bash: XXX: command not found解決辦法
- python virtualenv報錯-bash: virtualenv: command not foundPython
- bash: ssh-copy-id: command not found...
- zsh: command not found: bee bee工具安裝
- vim替換所有字元字元
- [20210930]IFS= read -r line.txt
- FFmpeg command line tool(Android中使用FFmpeg命令列)Android命令列
- Python系列(5)- 命令列應用 (Command Line Application)Python命令列APP
- Mac之telnet報錯-bash: telnet: command not foundMac