簡體   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