问题现象:

初学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

执行脚本 提示 command not found的更多相关文章

  1. 使用sudo执行命令提示command not found

    笔记: 使用源码部署nginx的时候,使用sudo nginx提示command not found,但是直接使用nginx会导致权限问题: 这种情况应该是环境变量导致的,使用 env |grep P ...

  2. ansible 远程执行时提示 command not found 问题

    问题 最近在学习 ansible ,在使用普通用户远程执行 ip a 命令是发现提示错误:/bin/sh: ip: command not found. 原因 command not found 命令 ...

  3. windows 上jenkins slave 执行脚本提示成功,但是没有运行

    控制台结果,但是脚本没有运行Started by user admin Building remotely on test_1110 in workspace D:\jenkins\workspace ...

  4. SSH非交互式密码授权远程执行脚本

    公司有上百台服务器,需要为每台服务器都执行一个脚本,因为所有服务器的账号密码都是一样的,所以可以不用搭建ansible等自动化运维工具,我们直接通过SSH远程执行即可完成. 本文以三台服务器为例,系统 ...

  5. ssh执行远程服务器脚本 提示php: command not found

    ssh执行远程服务器脚本 提示php: command not found 设置环境变量 一台机器作为管理机,来管理其他服务器,并通过key认证,免密码登陆的. 在管理机上通过ssh登陆到其他服务器来 ...

  6. Azkaban实战,Command类型单一job示例,任务中执行外部shell脚本,Command类型多job工作flow,HDFS操作任务,MapReduce任务,HIVE任务

    本文转载自:https://blog.csdn.net/tototuzuoquan/article/details/73251616 1.Azkaban实战 Azkaba内置的任务类型支持comman ...

  7. shell脚本执行错误 $'\r':command not found

    shell脚本执行错误 $'\r':command not found Linux下有命令dos2unix 可以用一下命令测试 vi -b filename 我们只要输入dos2unix *.sh就可 ...

  8. 将window的shell脚本通过ftp传输到Linux服务器后, shell脚本中执行时提示“没有那个文件或目录”的解决办法

    出现bad interpreter:No such file or directory的原因,是文件格式的问题.这个文件是在Windows下编写的.换行的方式与Unix不一样,但是在vim下面如果不S ...

  9. sudo执行提示Command not found

    运行一命令在普通用户下可行,切换到root用户依然可行,但在普通用户下使用sudo执行时,提示Command not found. 修改/etc/sudoers文件,找到类似下面的一行: Defaul ...

随机推荐

  1. 【CQ18高一暑假前挑战赛5】标程

    [A:暴力] #include<bits/stdc++.h> using namespace std; ; int a[maxn],vis[maxn],N,M; int main() { ...

  2. 【CQ18高一暑假前挑战赛3.5】标程

    [A:快速幂相关] #include<bits/stdc++.h> using namespace std; int qpow(int a,int x){ a%=;; while(x){ ...

  3. 中缀表达式std

    #include<cstdio>#include<cstdlib>#include<string>#include<cstring>using name ...

  4. DBCPTool

    dbcp读取配置文件的方式: 1. 导入3个包:commons-dbcp-...  .jar(数据源) commons-collections-.....jar(集合) commons-pool... ...

  5. linux下实现目录即文件的完整删除

    功能: 1.删除目录 2.删除文件 3.删除不为空的目录即下属文件 #ifndef _DELETE_FILE #define _DELETE_FILE #include <sys/stat.h& ...

  6. python optparse模块的简单用法

    # coding = utf-8 from optparse import OptionParser from optparse import OptionGroup usage = 'Usage: ...

  7. dos窗口的乱码问题

    1.在dos窗口上输入chcp 65001 2.然后右键属性选择字体

  8. CreateEx

    virtual BOOL CreateEx( DWORD dwExStyle, LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle ...

  9. http://www.cnblogs.com/dasenglin/p/5821987.html

    一安装maven 先安装jdk,配置JAVA_HOME 把下载的maven bin包,解压到指定目录,比如:D:\apache-maven-3.3.9-bin 配置maven的系统变量M2_HOME和 ...

  10. C和FORTRAN的快速傅里叶/余弦/正弦变换(Fast Fourier/Cosine/Sine Transform)开源库分享

    Takuya Ooura: General Purpose FFT Package, http://www.kurims.kyoto-u.ac.jp/~ooura/fft.html. Free C & ...