执行脚本 提示 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 ...
随机推荐
- 树莓派保持网络连接shell脚本
源:http://www.jianshu.com/p/96aa26d165c3 (我的简书文章) 故事背景 树莓派3b现在有了板载无线网卡,可以很方便的连接到wifi.但是无线路由器不能保证永远正常工 ...
- 测试工程师面试题之:给你印象最深的Bug
有人看到别人在侵淫面试技巧,什么<程序员面试宝典>,或者<面试测试工程师须知>等等,就会嗤之以鼻.他会觉得这不是“投机取巧”吗,最重要的还是踏实提高自己的能力. 非常同意这种看 ...
- zoj 2316 Matrix Multiplication 解题报告
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2316 题目意思:有 N 个 点,M 条 边.需要构造一个N * ...
- php字符串啊的heredoc格式
Heredoc技术,在正规的PHP文档中和技术书籍中一般没有详细讲述,只是提到了这是一种Perl风格的字符串输出技术.它也出现unix/linux的shell编程里面.但是现在的一些论坛程序,和部分文 ...
- codeforces 701A A. Cards(水题)
题目链接: A. Cards 题意: 问两个数的和相同,怎么组合; AC代码: #include <iostream> #include <cstdio> #include & ...
- 理解 Android Fragment
/***************************************************************************************** * 理解 Andr ...
- bzoj1013高斯消元
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1013 似乎是很明显的高斯消元: 第一次写高斯消元. 代码如下: #include<io ...
- Coloring Brackets
题意: 给一匹配的括号序列,要求每对括号恰有一个被染成蓝或红色,要求相邻的括号不同色,求方案数. 解法: 类比树的hash将括号序列转化为一棵树,树上子节点之间不得出现冲突, 子节点和父节点不得出现冲 ...
- B. Vanya and Food Processor【转】
B. Vanya and Food Processor time limit per test 1 second memory limit per test 256 megabytes input s ...
- 启动Android模拟器问题集锦
1.新建AVD时,报错“no CPU/ABI system image available for this target”, 解决:在SDK Manager中下载System Image 2.Sys ...