執行腳本 提示 command not found


 問題現象:

 

 

初學shell,寫了個腳本,

1.從windows 寫好 腳本,然后部署到 linux 上。

2.chmod +x之后執行提示command not found,系統環境redhat9,用echo $SHELL檢查shell版本顯示為/bin/bash,為了排錯,寫了一個最簡單的文件testfile,內容如下:

#!/bin/bash
echo "hello linux shell"

執行chmod +x testfile,運行,錯誤如前。

請各位大大指點

 

解決方法:

 dos2unix test.sh 

 

#############

命令簡介:

 

 

dos2unix是將Windows格式文件轉換為Unix、Linux格式的實用命令。Windows格式文件的換行符為\r\n ,而Unix&Linux文件的換行符為\n. dos2unix命令其實就是將文件中的\r\n 轉換為\n。

而unix2dos則是和dos2unix互為孿生的一個命令,它是將Linux&Unix格式文件轉換為Windows格式文件的命令。

 

 

命令語法

 

 

dos2unix [options] [-c convmode] [-o file ...] [-n infile outfile ...]

 

unix2dos [options] [-c convmode] [-o file ...] [-n infile outfile ...]

 

 

命令參數:

 

 

此命令參數是Red Hat Enterprise Linux Server release 5.7下dos2unix命令參數,不同版本Linux的dos2nnix命令參數有可能不同。

參數

長參數

描敘

-h

 

顯示命令dos2unix聯機幫助信息。

-k

 

保持文件時間戳不變

-q

 

靜默模式,不輸出轉換結果信息等

-V

 

顯示命令版本信息

-c

 

轉換模式

-o

 

在源文件轉換,默認參數

-n

 

保留原本的舊檔,將轉換后的內容輸出到新檔案.默認都會直接在原來的文件上修改,

 

 

 

使用示例:

 

 

1: 查看dos2unix命令的幫助信息

[root@DB-Server myscript]# man dos2unix
 
[root@DB-Server myscript]# dos2unix -h
dos2unix Copyright (c) 1994-1995 Benjamin Lin
         Copyright (c) 1998      Bernd Johannes Wuebben (Version 3.0)
         Copyright (c) 1998      Christian Wurll (Version 3.1)
Usage: dos2unix [-hkqV] [-c convmode] [-o file ...] [-n infile outfile ...]
 -h --help        give this help
 -k --keepdate    keep output file date
 -q --quiet       quiet mode, suppress all warnings
                  always on in stdin->stdout mode
 -V --version     display version number
 -c --convmode    conversion mode
 convmode         ASCII, 7bit, ISO, Mac, default to ASCII
 -l --newline     add additional newline in all but Mac convmode
 -o --oldfile     write to old file
 file ...         files to convert in old file mode
 -n --newfile     write to new file
 infile           original file in new file mode
 outfile          output file in new file mode

 

2: dos2unix filename 將Windows格式文本轉換為Unix&Linux格式文件

   1: [root@DB-Server myscript]# cat -v test.sh 
   2: . /home/oracle/.bash_profile^M
   3: echo ' '^M
   4: date^M
   5: echo ' '^M
   6: ^M
   7: sqlplus test/test @/home/oracle/scripts/test.sql^M
   8: ^M
   9: echo ' '^M
  10: date^M
  11: echo ' '^M
  12: [root@DB-Server myscript]# dos2unix test.sh 
  13: dos2unix: converting file test.sh to UNIX format ...
  14: [root@DB-Server myscript]# cat -v test.sh 
  15: . /home/oracle/.bash_profile
  16: echo ' '
  17: date
  18: echo ' '
  19:  
  20: sqlplus test/test @/home/oracle/scripts/test.sql
  21:  
  22: echo ' '
  23: date
  24: echo ' '

 

3: dos2unix 可以一次轉換多個文件

   1: dos2unix filename1 filename2 filename3

 

 

1.https://www.cnblogs.com/kerrycode/archive/2015/12/26/5077969.html

2.http://bbs.chinaunix.net/thread-681229-1-1.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM