linux - 在 Windows 机器中从 powershell 执行 shell 脚本

标签 linux bash shell

我正在尝试从 Windows 机器的 power shell 执行 shell 脚本。所以开始编写 shell 脚本并使用以下命令调用到 linux 框中:

PS>.\pscp.exe .\abc.sh root@1.2.3.4:/root` and gave the permissions through power shell by using below command  
PS>.\plink.exe -pw "L***e" root@1.2.3.4 -P 22 "chmod +x abc.sh"` after that verified that shell script copied or not  
PS>.\plink.exe -pw "L***e" root@1.2.3.4 -P 22 "ls"

所以它复制了。之后,当我使用以下命令执行时:

PS>.\plink.exe -pw "L***e" root@1.2.3.4 -P 22 "bash ./abc.sh"`

从某种意义上说它不起作用,会出现如下错误:

./abc.sh: line 4: $'\r': command not found ./abc.sh: 
line 5: syntaxerror near unexpected token `$'\r'' '/abc.sh: 
line 5: `function abc()
PS>.\plink.exe -pw "L***e" root@1.2.3.4 -P 22 "./abc.sh"
bash: ./abc.sh: /bin/bash^M: bad interpreter: No such file or directory

如果有任何宝贵的建议,在此先感谢......

最佳答案

我没有使用太多的 Windows 文本编辑器,但是“^M:错误的解释器:没有那个文件或目录”- 表示有回车的 Windows 版本。因此,将您的脚本文件转换为 unix 风格可能会有所帮助。

引用:https://kb.iu.edu/d/acux

关于linux - 在 Windows 机器中从 powershell 执行 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42350189/

相关文章:

bash - 这些重定向和文件描述符的目的是什么?

shell - Unix 猫 : No such file or directory error

python - 要在 python 中打印特定的文件夹名称?

python - 解释了正确的守护程序行为(来自PEP 3143)

linux - 对 "kernel process"的疑问

linux - crontab @reboot 在服务器重启时不执行 bash 脚本

linux - 检查命令是否在 bash 中的 if 中执行

android - C语言怎么写, "ip -6 route add default dev wlan0"

bash - 使用$?在 bash 函数中

linux - bash:检查目录中的多个文件是否包含列表中的字符串