简体   繁体   English

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

[英]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.

相关问题 如何在Shell脚本中以非root用户身份登录(同时使用用户名和密码)? - How to login (using both username and password) as a non root user in linux in a shell script? 如何在Shell Script中制作scp要求我输入密码 - How to make scp in Shell Script ask me for password linux bash shell:如何使用文件中的用户名和密码创建用户? - linux bash shell: how to create user with username and password from file? 如何从shell脚本文件中读取用户名和密码? - how to read username & password from file in shell script? 如何使用Shell脚本将用户名和密码传递给应用程序? - How to pass Username and password to an application using shell script? 如何设置Linux服务器Wordpress插件或主题下载服务器询问FTP主机名,FTP用户名,FTP密码。 - How to Set Linux server Wordpress Plugin or Themes download server ask FTP hostname , FTP Username , FTP password .? 如何在Windows环境中运行Linux Shell脚本 - How to run Linux shell script on windows environment 如何在Windows上的Linux中启动Shell脚本制作 - How to launch a shell script make with Linux on Windows 使用Python脚本更改Linux用户名或密码 - Changing Linux username or password with Python script Linux Bash Shell脚本,密码隐藏为Truecrypt - Linux bash shell script with password hide for truecrypt
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM