How do -s and -p alter the read command?

风流意气都作罢 提交于 2021-02-17 05:36:06

问题


I'm trying to interpret this block of code. Searched google to see what these commands mean and no luck. I put my interpretation of what each line/block means to me. If I am wrong, please correct me. I am new to unix commands. Code:

#!/bin/bash    

# input 1st command line argument for the version.  
export VERSION=$1

# if user didn't input a version, print the echo message and exit (not sure what -n means but I am assuming)
if [[ ! -n "$VERSION" ]]; then
    echo "Missing Version"
    exit 1
fi

# creating variable UNAME that tells who the person is (their name)
export UNAME='whoami'

# no idea what -s and -p mean but i think this prints the message "enter password for $UNAME" and stores it in a new variable named PASSWORD. the $UNAME will print whatever whoami said.
read -s -p "Enter password for $UNAME: " PASSWORD
echo ""

回答1:


The -p flag issues a prompt before reading input into a variable

The -s flag stop the typed response from being shown (i.e. for a sensitive password)

More information is available here:

https://linuxhint.com/bash_read_command/




回答2:


  -p

prompt output the string PROMPT without a trailing newline before attempting to read.

  -s

do not echo input coming from a terminal.



来源:https://stackoverflow.com/questions/64355370/how-do-s-and-p-alter-the-read-command

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!