如何在 Red Hat 中运行 .sh 文件?

Cha*_*rly 2 linux redhat shell command-line-interface

当我尝试.sh使用 Redhat运行我的文件时./test.sh

我收到类似的错误

[test@tester unix_scripts]$ ./test.sh
: No such file or directory
[test@tester unix_scripts]$ 
Run Code Online (Sandbox Code Playgroud)

我还设置了文件的权限 chmod 777 test.sh

还是同样的错误

有谁能够帮助我?

Cha*_*rly 6

实际上问题是我使用的脚本是在 dos 中创建的,所以我使用 dos2unix 命令将我的脚本转换为 unix。感谢大家的宝贵帮助。

  • dos2unix 也经常为我修复这些问题。如果在第一行添加了 Win 换行符 - unix 现在找不到 /bin/sh 了,因为它现在是 /bin/sh^M (3认同)
  • dos2unix 仅将 DOS 换行符转换为 UNIX 样式的换行符。它不会用魔法使脚本与 shell 兼容。 (2认同)