📄 getans
字号:
#!/bin/sh# getans prompt type default results_filename# type is one of # number # integer# neginteger# file default=default filename# path # yesno default=0,1 corres yes or no # string (default)RAWPMPT=$1TYP=$2DFLT=$3OFNM=$4ny0="no"; ny1="yes"if [ ${TYP} = "yesno" ]; then eval ny=\$ny${DFLT} pmpt="${RAWPMPT} [$ny]: "else if [ -z "${DFLT}" ]; then pmpt="${RAWPMPT}" else pmpt="${RAWPMPT} [${DFLT}]: " fifiif [ x"`echo -n`" = x-n ]then c=\\celse n=-nfiwhile :do echo $n "$pmpt"$c read input case "$TYP" in number) tmp=`echo $input | tr -d 0123456789.` if [ -n "$tmp" ]; then echo "Invalid number. Please try again." continue fi ;; integer) tmp=`echo $input | tr -d 0123456789` if [ -n "$tmp" ]; then echo "Invalid integer. Please try again." continue fi ;; neginteger) if [ "x$input" != "x-1" ]; then tmp=`echo $input | tr -d 0123456789` if [ -n "$tmp" ]; then echo "Invalid integer. Please try again." continue fi fi ;; file) if [ -z "$input" ]; then input=${DFLT} fi if [ ! -f "$input" -a ! -d "$input" ]; then echo "The file $input does not exist. Please try again." continue fi ;; path) if [ -z "$input" ]; then input="${DFLT}" fi if [ ! -f "$input" ]; then path=`echo $PATH | sed -e s'/::/ . /g' -e 's/:/ /g'` x= for elt in $path; do if [ -f "$elt/$input" ]; then x=1; break; fi done if [ -z "$x" ] ;then echo "The command $input was not found. Please try again." continue fi fi ;; yesno) if [ -z "$input" ]; then input="${DFLT}" else case $input in y | yes) input=1 ;; n | no) input=0 ;; *) echo 'Please answer "yes" or "no".' continue ;; esac fi ;; *) ;; esac breakdoneif [ -z "$input" ]; then input="${DFLT}"fiecho $input > ${OFNM}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -