执行脚本 提示 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
执行脚本 提示 command not found的更多相关文章
- 使用sudo执行命令提示command not found
笔记: 使用源码部署nginx的时候,使用sudo nginx提示command not found,但是直接使用nginx会导致权限问题: 这种情况应该是环境变量导致的,使用 env |grep P ...
- ansible 远程执行时提示 command not found 问题
问题 最近在学习 ansible ,在使用普通用户远程执行 ip a 命令是发现提示错误:/bin/sh: ip: command not found. 原因 command not found 命令 ...
- windows 上jenkins slave 执行脚本提示成功,但是没有运行
控制台结果,但是脚本没有运行Started by user admin Building remotely on test_1110 in workspace D:\jenkins\workspace ...
- SSH非交互式密码授权远程执行脚本
公司有上百台服务器,需要为每台服务器都执行一个脚本,因为所有服务器的账号密码都是一样的,所以可以不用搭建ansible等自动化运维工具,我们直接通过SSH远程执行即可完成. 本文以三台服务器为例,系统 ...
- ssh执行远程服务器脚本 提示php: command not found
ssh执行远程服务器脚本 提示php: command not found 设置环境变量 一台机器作为管理机,来管理其他服务器,并通过key认证,免密码登陆的. 在管理机上通过ssh登陆到其他服务器来 ...
- Azkaban实战,Command类型单一job示例,任务中执行外部shell脚本,Command类型多job工作flow,HDFS操作任务,MapReduce任务,HIVE任务
本文转载自:https://blog.csdn.net/tototuzuoquan/article/details/73251616 1.Azkaban实战 Azkaba内置的任务类型支持comman ...
- shell脚本执行错误 $'\r':command not found
shell脚本执行错误 $'\r':command not found Linux下有命令dos2unix 可以用一下命令测试 vi -b filename 我们只要输入dos2unix *.sh就可 ...
- 将window的shell脚本通过ftp传输到Linux服务器后, shell脚本中执行时提示“没有那个文件或目录”的解决办法
出现bad interpreter:No such file or directory的原因,是文件格式的问题.这个文件是在Windows下编写的.换行的方式与Unix不一样,但是在vim下面如果不S ...
- sudo执行提示Command not found
运行一命令在普通用户下可行,切换到root用户依然可行,但在普通用户下使用sudo执行时,提示Command not found. 修改/etc/sudoers文件,找到类似下面的一行: Defaul ...
随机推荐
- 谈谈网站测试中的AB测试方法
什么是A/B测试? A / B测试,即你设计的页面有两个版本(A和B),A为现行的设计, B是新的设计.比较这两个版本之间你所关心的数据(转化率,业绩,跳出率等) ,最后选择效果最好的版本. A / ...
- 通过kettle数据导入mysql时,空值的处理在插入mysql时,会自动转转换为null值,无法插入
1.windows下C:\Users\用户名\.kettle目录中找到kettle.properties文件,增加KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL=Y2.Li ...
- 为什么在启动linux后进入终端提示sh-3.2#
这是Linux系统环境变量设置问题,用户登陆后确保是root权限,可以用如下这两条命令解决:-bash-3.2# cp /etc/skel/.{bash_profile,bashrc} ~-bash- ...
- 八、子查询、limit及limit的分页
1.子查询 定义:select语句中嵌套select语句被称为子查询 select子句可能出现在select.from.where关键字后面,如下: A.将一个表的查询结果当做是过滤条件 B.将一个表 ...
- 关于try catch finally的执行顺序解释
偶然遇到了被问到finally的执行问题,忽然发现一直用的都是try catch 没有用过finally的情况,所以目前总结一下. 先抛出结论: 1.try内部正常执行try的内部逻辑,异常则执行ca ...
- Python的中文处理
一.使用中文字符 在python源码中如果使用了中文字符,运行时会有错误,解决的办法是在源码的开头部分加入字符编码的声明,下面是一个例子: #!/usr/bin/env python # -*- co ...
- Python_列表,元组和字典的异同
1,列表:list 可变的数据类型,可以被改变,可以进行嵌套处理,可在一个列表中存储一个序列的项目 指明一个列表的方法是:使用方括号 代码示例: >>> fruit_list = [ ...
- CF-807A
A. Is it rated? time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- 【Hadoop】MapReduce笔记(四):MapReduce优化策略总结
Cloudera 提供给客户的服务内容之一就是调整和优化MapReduce job执行性能.MapReduce和HDFS组成一个复杂的分布式系统,并且它们运行着各式各样用户的代码,这样导致没有一个快速 ...
- 1-1 课程简介 & 2-1 IDEA与Eclipse的不同 & 2-3 Intellij IDEA安装
---恢复内容开始--- F:\教程\java-慕课\从网页搭建入门Java Web\Java web\步骤四:常用功能\1.IntelliJ IDEA开发工具入门 1-1 课程简介 2-1 IDEA ...