所需:
如何将值传递给-p <parameter value>
(“密码”)而不在命令行中以明文形式将其最终存储在bash_history中?可以将其存储在文件中并使用cat <file>
密码吗?
实际:
密码显示在命令行bash_history中。
用法:
sh test.sh -u username -p password
代码:
#!/bin/sh
OPTS=`getopt -o up: --long username,password -n 'parse-options' -- "$@"`
DOCKER_OPTS=""
while true; do
case "$1" in
-u | --username)
USER="$2"; shift; shift;;
-p | --password)
PASS="$2"; shift; shift ;;
* ) break ;;
esac
done
if [ -z "$USER" ] || [ -z "$PASS" ] ; then
echo "username and pass not defined"
else
echo "username and password defined"
fi
答案 0 :(得分:-1)
好的,我找到了答案。.抱歉
sh test.sh -u username -p $(< pass.txt)