执行脚本 提示 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 ...
随机推荐
- H5与native有啥区别?
app测试,H5与native有啥区别? native是使用原生系统内核的,相当于直接在系统上操作.是我们传统意义上的软件,更加稳定. 但是H5的APP先得调用系统的浏览器内核,相当于是在网页中进行操 ...
- Spring MVC 注解json 配置
1.首先在pom.xml中添加依赖jar包 <dependency> <groupId>org.codehaus.jackson</groupId> ...
- 深入攻克c语言--day04
1.将包含字符数字的字符串分开,使得分开后的字符串前一部分是数字后一部分是字母.例 如“h1ell2o3” ->”123hello” #include<stdio.h> #inclu ...
- Azure Key Vault (2) 使用Azure Portal创建和查看Azure Key Vault
<Windows Azure Platform 系列文章目录> 请注意: 文本仅简单介绍如何在Azure Portal创建和创建Key Vault,如果需要结合Application做二次 ...
- web数据存储
数据的存储必然是任何网站必须经历的事,我们可以将数据存放在不同地方,数据库.文件.内存.程序本身.cookie,session中都可以,但是只要需要持久化保留的数据,那么最终肯定还是落在磁盘之上的,我 ...
- CodeForces 1110G. Tree-Tac-Toe
题目简述:给定$n$个节点的树,其中一些节点被染成了白色(其余节点未染色).黑白双方博弈,白先动.轮到黑(白)方时,选择树上的一个未染色的节点并将其染成黑(白)色.率先达成三连色(即存在三个节点$a, ...
- CF-831B
B. Keyboard Layouts time limit per test 1 second memory limit per test 256 megabytes input standard ...
- In-App Purchase Programming Guide----(一) ---- About In-App Purchase
About In-App Purchase In-App Purchase allows you to embed a store inside your app using the Store Ki ...
- Python 之IO模型
阻塞IO模型:以前写的套接字通信都是阻塞型的.通过并发提高效率 非阻塞IO模型: from socket import * # 并不推荐使用,一是消耗cpu资源,二是会响应延迟 server = so ...
- c语言中的# ## 可变参数宏 ...和_ _VA_ARGS_ _
1.#假如希望在字符串中包含宏参数,ANSI C允许这样作,在类函数宏的替换部分,#符号用作一个预处理运算符,它可以把语言符号转化程字符串.例如,如果x是一个宏参量,那么#x可以把参数名转化成相应的字 ...