执行Linux脚本,出现No Such file or directory异常

最近在学习Linux系统的脚本开发,在我编写完标本的情况出现了以下的情况

这个时候出现了No Such file or directory 情况出现 ,提示文件不存在;

但是通过VIM命令访问此脚本,是能够进入此脚本的

这个时候我猜测,可能是由于编码问题引起的,因为我在编写此脚本的时候我是在Windos系统中使用nodpad++编写(nodpad的编码格式此时为ANSI);然后通过Secure连接至Linux服务器,进行粘贴。

我继续在VIM编辑下通过:set ff? 发现编码格式如下:

发现编码格式为DOS,DOS中会存在不可见字符,会导致Linux执行失败

这个时候我们可以通过:set ff=unix 转换格式为Unix,修改完保存退出,再次执行我的脚本就可以指定成功了.

原文地址:https://www.cnblogs.com/diandain/p/8850269.html

时间: 2024-08-03 14:43:34

执行Linux脚本,出现No Such file or directory异常的相关文章

执行linux脚本出现问题

1. 权限不够: 使用 chmod +x XXX.sh 提升权限 2. 出现:/bin/bash^M: bad interpreter: No such file or directory 原因:文件换行里出现\r\n  与linux格式不符合 安装dos2unix   apt-get install dos2unix 然后使用命令:#dos2unix myshell.sh  转换就行 执行linux脚本出现问题,布布扣,bubuko.com

Runtime.getRuntime.exec()执行linux脚本导致程序卡死有关问题

Runtime.getRuntime.exec()执行linux脚本导致程序卡死问题问题: 在Java程序中,通过Runtime.getRuntime().exec()执行一个Linux脚本导致程序被挂住,而在终端上直接执行这个脚本则没有任何问题.原因: 先来看Java代码: public final static void process1(String[] cmdarray) {        Process p = null;        BufferedReader br = null

调用Runtime.getRuntime().exec()执行Linux脚本防挂死和返回脚本输出

1.在实际开发中,使用Runtime.getRuntime().exec()执行Linux脚本时,需要同时读取标准输出流与错误输出流缓冲区数据,因为操作系统缓冲区大小有限制,不及时处理会导致缓冲区占满而挂住,这种问题发生在于开发人员对该接口不了解而引发Bug. 具体可以通过使用两个线程同时去读错误和标准输出流缓冲区数据,然后用proc.waitFor()可以获取执行的结果.这种事最常见的场景,只关注脚本执行结果. 2.但在实际开发中,通过Runtime.getRuntime().exec()执行

Linux执行.sh文件,提示No such file or directory的问题的解决方法

Linux执行.sh文件,提示No such file or directory的问题在window平台下,写好shell脚本文件,迁移到linux平台,赋过可执行权限,执行该sh文件,却提示No such file or directory.ls 了下,确实有该文件,怎么会事呢,难道是文件格式兼容性问题?用vim打开该sh文件,输入:[plain]:set ff 回车,显示fileformat=dos,重新设置下文件格式:[plain]:set ff=unix 保存退出:[plain]:wq 

PHP执行linux脚本

PHP执行linux命令,需要用到几个方法,比如system() exec() passthru() 我用的是exec() 执行一个脚本 <?php $result="/opt/1.sh"; exec($result,$res,$ret); if($ret == "0") { echo "true"; }else{ echo "false"; } 网页访问,返回false 加sudo测试 在linux系统编辑配置文件 v

hadoop 启动后执行wordcount解析(No such file or directory错误)

hadoop 启动后执行wordcount解析 第一个  hadoop fs -mkdir input 结果出现了错误No such file or directory 查资料,应该是 执行命令为:hadoop fs -mkdir /input 1.x是可以执行的,而2.x的执行命令为:hadoop fs -mkdir /

linux/module.h: No such file or directory 内核模块编译过程

1.缺少Linux kernel头文件 To install just the headers in Ubuntu: sudo apt-get install linux-headers-$(uname -r) To install the entire Linux kernel source in Ubuntu: sudo apt-get install linux-source Note that you should use the kernel headers that match th

Linux System Programming note 8 ——File and Directory Management

1. The Stat Family #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> int stat(const char *path, struct stat *buf); int fstat(int fd, struct stat *buf); int lstat(const char *path, struct stat *buf); struct stat{ dev_t st_d

linux脚本报错 /root:is a directory

报错信息:./123.sh :line 20:/root:is a directory 报错:/root:is a directory ,然后从脚本文件找root,发现脚本里并没有root由于多了个~导致报错 标红的"~"是粘贴的时候带过去的将~删除,解决 原文地址:https://blog.51cto.com/13555423/2476067