gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 09:20:37 27 4
gpt4 key购买 nike

我正在尝试从 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com