[英]how to ask for username and password with a shell script on linux and windows
I need to ask for username and password from a.sh script for linux and windows, how is this possible?我需要从 linux 和 windows 的 a.sh 脚本中询问用户名和密码,这怎么可能?
i tried this but it doesn't work:我试过这个但它不起作用:
#!/bin/bash
echo "Type the username, followed by [ENTER]:"
read username
echo "Type the password, followed by [ENTER]:"
read -s password
echo "The name entered was: $username"
echo "The path entered was: $password"
On linux and Windows terminal i get this:在 linux 和 Windows 终端我得到这个:
>>bash try.sh
try.sh: line 2: $'\r': command not found
Type the username, followed by [ENTER]:
try.sh: line 4: $'\r': command not found
': not a valid identifierername
try.sh: line 6: $'\r': command not found
Type the password, followed by [ENTER]:
try.sh: line 8: $'\r': command not found
': not a valid identifierssword
try.sh: line 10: $'\r': command not found
The name entered was:
The path entered was:
I think your files have as line separators \r\n
, which is vaid on windows but not on linux (at least for scripts intended to be read by bash).我认为您的文件具有行分隔符
\r\n
,这在 windows 上有效,但在 linux 上无效(至少对于旨在由 bash 读取的脚本)。 On linux the line separator should be \n
在 linux 上,行分隔符应为
\n
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.