得到错误“:找不到命令";尝试运行shell脚本时 [英] Getting error ": command not found" when trying to run shell script

查看:65
本文介绍了得到错误“:找不到命令";尝试运行shell脚本时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在尝试运行的脚本,但是每当我尝试运行该脚本时,都会出现错误:not found".这是我尝试修复的方法:

  1. 确保hashbang是正确的#!/bin/bash"
  2. 在文件上运行dos2unix
  3. 以scriptname.sh,./scriptname.sh和/bin/bash scriptname.sh运行脚本
  4. chmod 755脚本名.sh

我仍然无法运行该脚本.任何帮助深表感谢!

解决方案

这是由回车引起的.以下是 bash标签Wiki 的摘录:

  1. 检查您的脚本或数据是否具有DOS样式的行尾字符

    • 使用 cat -v yourfile echo"$ yourvariable" |cat -v .

      DOS回车符将在每行后显示为 ^ M .

      如果找到它们,请使用 dos2unix (又名 fromdos )或 tr -d'\ r'

确保检查所有数据,而不仅仅是脚本本身.

I have a script that I'm trying to run but I just get the error ": command not found" whenever I try to run it. Here's what I've tried to do to fix it:

  1. Made sure the hashbang is correct "#!/bin/bash"
  2. Run dos2unix on the file
  3. Run the script as scriptname.sh, ./scriptname.sh, and /bin/bash scriptname.sh
  4. chmod 755 scriptname.sh

I still am unable to run the script. Any help is much appreciated!

解决方案

This is caused by carriage returns. Here's the excerpt from the bash tag wiki:

  1. Check whether your script or data has DOS style end-of-line characters

    • Use cat -v yourfile or echo "$yourvariable" | cat -v .

      DOS carriage returns will show up as ^M after each line.

      If you find them, delete them using dos2unix (a.k.a. fromdos) or tr -d '\r'

Make sure to check all your data, and not just the script itself.

这篇关于得到错误“:找不到命令";尝试运行shell脚本时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆