首页 > 解决方案 > -s 和 -p 如何更改读取命令?

问题描述

我正在尝试解释这段代码。搜索谷歌以查看这些命令的含义,但没有运气。我解释了每行/块对我的意义。如果我错了,请纠正我。我是 unix 命令的新手。代码:

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

标签: linuxbashunix

解决方案


  -p

在尝试读取之前提示输出不带尾随换行符的字符串 PROMPT。

  -s

不要回显来自终端的输入。


推荐阅读