admin管理员组文章数量:1192529
When I run the script test.sh below from an MSYS2 terminal on Windows the newlines are not honored in the ssh command. The remote shell is cmd and the file is saved with Windows line endings (CR LF). Any ideas?
$ cat test.sh
text=$(cat <<'EOF'
hello
there
EOF
)
printf "%s\n\n" "$text"
ssh A-WINDOWS-SERVER $(cat <<'EOF'
echo hello
echo there
EOF
)
$ sh test.sh
hello
there
hello echo there
When I run the script test.sh below from an MSYS2 terminal on Windows the newlines are not honored in the ssh command. The remote shell is cmd and the file is saved with Windows line endings (CR LF). Any ideas?
$ cat test.sh
text=$(cat <<'EOF'
hello
there
EOF
)
printf "%s\n\n" "$text"
ssh A-WINDOWS-SERVER $(cat <<'EOF'
echo hello
echo there
EOF
)
$ sh test.sh
hello
there
hello echo there
Share
Improve this question
asked Jan 23 at 19:16
August KarlstromAugust Karlstrom
11.4k8 gold badges44 silver badges69 bronze badges
2
- What environment does your Windows ssh server provide? The normal Windows shell doesn't understand "cat". – Tim Roberts Commented Jan 23 at 19:20
- @TimRoberts It's only the MSYS2 shell which will execute the cat commands. – August Karlstrom Commented Jan 23 at 19:28
1 Answer
Reset to default 2The problem here actually occurs in the original script, not in the ssh command. Remember that the $(...) gets executed locally, not remotely. Notice this, executed in Linux:
timr@Tims-NUC:~/src$ echo $(cat <<EOF
> hello
> there
> EOF
> )
hello there
timr@Tims-NUC:~/src$
What you're doing here is converting words from the "file" into command line arguments. The white space all gets removed. Your command ends up being
ssh A-WINDOWS-SERVER echo hello echo there
and that's exactly what you see.
If you want to pass multiple commands through the ssh, pass them via stdin, not via the command line.
本文标签: msys2Why are newlines not honored in SSH command on WindowsStack Overflow
版权声明:本文标题:msys2 - Why are newlines not honored in SSH command on Windows? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738471148a2088596.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论