繁体   English   中英

如何使用 linux 和 windows 上的 shell 脚本询问用户名和密码

[英]how to ask for username and password with a shell script on linux and windows

我需要从 linux 和 windows 的 a.sh 脚本中询问用户名和密码,这怎么可能?

我试过这个但它不起作用:

#!/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"

在 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:  

我认为您的文件具有行分隔符\r\n ,这在 windows 上有效,但在 linux 上无效(至少对于旨在由 bash 读取的脚本)。 在 linux 上,行分隔符应为\n

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM