执行脚本 提示 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

转载于:https://www.cnblogs.com/feiyun8616/p/7988712.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值