Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b490a32

Browse files
committed
improve shell read -e -p
1 parent 51576e9 commit b490a32

10 files changed

Lines changed: 113 additions & 113 deletions

addons.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ ACTION_FUN() {
154154
echo "Please select an action:"
155155
echo -e "\t${CMSG}1${CEND}. install"
156156
echo -e "\t${CMSG}2${CEND}. uninstall"
157-
read -p "Please input a number:(Default 1 press Enter) " ACTION
157+
read -e -p "Please input a number:(Default 1 press Enter) " ACTION
158158
[ -z "${ACTION}" ] && ACTION=1
159159
if [[ ! "${ACTION}" =~ ^[1,2]$ ]]; then
160160
echo "${CWARNING}input error! Please only input number 1~2${CEND}"
@@ -180,7 +180,7 @@ What Are You Doing?
180180
\t${CMSG}11${CEND}. Install/Uninstall ngx_lua_waf
181181
\t${CMSG} q${CEND}. Exit
182182
"
183-
read -p "Please input the correct option: " Number
183+
read -e -p "Please input the correct option: " Number
184184
if [[ ! "${Number}" =~ ^[1-9,q]$|^1[0-1]$ ]]; then
185185
echo "${CFAILURE}input error! Please only input 1~11 and q${CEND}"
186186
else
@@ -193,7 +193,7 @@ What Are You Doing?
193193
echo -e "\t${CMSG}2${CEND}. XCache"
194194
echo -e "\t${CMSG}3${CEND}. APCU"
195195
echo -e "\t${CMSG}4${CEND}. eAccelerator"
196-
read -p "Please input a number:(Default 1 press Enter) " phpcache_option
196+
read -e -p "Please input a number:(Default 1 press Enter) " phpcache_option
197197
[ -z "${phpcache_option}" ] && phpcache_option=1
198198
if [[ ! "${phpcache_option}" =~ ^[1-4]$ ]]; then
199199
echo "${CWARNING}input error! Please only input number 1~4${CEND}"
@@ -233,7 +233,7 @@ What Are You Doing?
233233
2)
234234
if [[ "${PHP_main_ver}" =~ ^5.[3-6]$ ]]; then
235235
while :; do
236-
read -p "Please input xcache admin password: " xcachepwd
236+
read -e -p "Please input xcache admin password: " xcachepwd
237237
(( ${#xcachepwd} >= 5 )) && { xcachepwd_md5=$(echo -n "${xcachepwd}" | md5sum | awk '{print $1}') ; break ; } || echo "${CFAILURE}xcache admin password least 5 characters! ${CEND}"
238238
done
239239
checkDownload
@@ -272,7 +272,7 @@ What Are You Doing?
272272
echo "Please select ZendGuardLoader/ionCube:"
273273
echo -e "\t${CMSG}1${CEND}. ZendGuardLoader"
274274
echo -e "\t${CMSG}2${CEND}. ionCube Loader"
275-
read -p "Please input a number:(Default 1 press Enter) " Loader
275+
read -e -p "Please input a number:(Default 1 press Enter) " Loader
276276
[ -z "${Loader}" ] && Loader=1
277277
if [[ ! "${Loader}" =~ ^[1,2]$ ]]; then
278278
echo "${CWARNING}input error! Please only input number 1~2${CEND}"
@@ -311,7 +311,7 @@ What Are You Doing?
311311
echo "Please select ImageMagick/GraphicsMagick:"
312312
echo -e "\t${CMSG}1${CEND}. ImageMagick"
313313
echo -e "\t${CMSG}2${CEND}. GraphicsMagick"
314-
read -p "Please input a number:(Default 1 press Enter) " magick_option
314+
read -e -p "Please input a number:(Default 1 press Enter) " magick_option
315315
[ -z "${magick_option}" ] && magick_option=1
316316
if [[ ! "${magick_option}" =~ ^[1,2]$ ]]; then
317317
echo "${CWARNING}input error! Please only input number 1~2${CEND}"
@@ -345,7 +345,7 @@ What Are You Doing?
345345
echo "Please select fileinfo/imap:"
346346
echo -e "\t${CMSG}1${CEND}. fileinfo"
347347
echo -e "\t${CMSG}2${CEND}. imap"
348-
read -p "Please input a number:(Default 1 press Enter) " phpext_option
348+
read -e -p "Please input a number:(Default 1 press Enter) " phpext_option
349349
[ -z "${phpext_option}" ] && phpext_option=1
350350
if [[ ! "${phpext_option}" =~ ^[1,2]$ ]]; then
351351
echo "${CWARNING}input error! Please only input number 1~2${CEND}"
@@ -390,7 +390,7 @@ What Are You Doing?
390390
echo -e "\t${CMSG}1${CEND}. memcache PHP Extension"
391391
echo -e "\t${CMSG}2${CEND}. memcached PHP Extension"
392392
echo -e "\t${CMSG}3${CEND}. memcache/memcached PHP Extension"
393-
read -p "Please input a number:(Default 1 press Enter) " Memcache
393+
read -e -p "Please input a number:(Default 1 press Enter) " Memcache
394394
[ -z "${Memcache}" ] && Memcache=1
395395
if [[ ! "${Memcache}" =~ ^[1-3]$ ]]; then
396396
echo "${CWARNING}input error! Please only input number 1~3${CEND}"

backup_setup.sh

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ while :; do echo
3838
echo -e "\t${CMSG}4${CEND}. Qcloud COS"
3939
echo -e "\t${CMSG}5${CEND}. UPYUN"
4040
echo -e "\t${CMSG}6${CEND}. QINIU"
41-
read -p "Please input a number:(Default 1 press Enter) " desc_bk
41+
read -e -p "Please input a number:(Default 1 press Enter) " desc_bk
4242
[ -z "${desc_bk}" ] && desc_bk=1
4343
ary=(1 2 3 4 5 6 12 13 14 15 16 23 24 25 26 34 35 36 45 46 56 123 124 125 126 134 135 136 145 146 156 234 235 236 245 246 256 345 346 456 1234 1235 1236 2345 2346 3456 12345 12346 13456 23456 123456)
4444
if [[ "${ary[@]}" =~ "${desc_bk}" ]]; then
@@ -62,7 +62,7 @@ while :; do echo
6262
echo -e "\t${CMSG}1${CEND}. Only Database"
6363
echo -e "\t${CMSG}2${CEND}. Only Website"
6464
echo -e "\t${CMSG}3${CEND}. Database and Website"
65-
read -p "Please input a number:(Default 1 press Enter) " content_bk
65+
read -e -p "Please input a number:(Default 1 press Enter) " content_bk
6666
[ -z "${content_bk}" ] && content_bk=1
6767
if [[ ! ${content_bk} =~ ^[1-3]$ ]]; then
6868
echo "${CWARNING}input error! Please only input number 1~3${CEND}"
@@ -78,7 +78,7 @@ done
7878
if [[ ${desc_bk} =~ ^[1,2]$ ]]; then
7979
while :; do echo
8080
echo "Please enter the directory for save the backup file: "
81-
read -p "(Default directory: ${backup_dir}): " new_backup_dir
81+
read -e -p "(Default directory: ${backup_dir}): " new_backup_dir
8282
[ -z "${new_backup_dir}" ] && new_backup_dir="${backup_dir}"
8383
if [ -z "`echo ${new_backup_dir}| grep '^/'`" ]; then
8484
echo "${CWARNING}input error! ${CEND}"
@@ -91,7 +91,7 @@ fi
9191

9292
while :; do echo
9393
echo "Please enter a valid backup number of days: "
94-
read -p "(Default days: 5): " expired_days
94+
read -e -p "(Default days: 5): " expired_days
9595
[ -z "${expired_days}" ] && expired_days=5
9696
[ -n "`echo ${expired_days} | sed -n "/^[0-9]\+$/p"`" ] && break || echo "${CWARNING}input error! Please only enter numbers! ${CEND}"
9797
done
@@ -101,7 +101,7 @@ if [ "${content_bk}" != '2' ]; then
101101
databases=`${db_install_dir}/bin/mysql -uroot -p$dbrootpwd -e "show databases\G" | grep Database | awk '{print $2}' | grep -Evw "(performance_schema|information_schema|mysql|sys)"`
102102
while :; do echo
103103
echo "Please enter one or more name for database, separate multiple database names with commas: "
104-
read -p "(Default database: `echo $databases | tr ' ' ','`) " db_name
104+
read -e -p "(Default database: `echo $databases | tr ' ' ','`) " db_name
105105
db_name=`echo ${db_name} | tr -d ' '`
106106
[ -z "${db_name}" ] && db_name="`echo $databases | tr ' ' ','`"
107107
D_tmp=0
@@ -118,7 +118,7 @@ if [ "${content_bk}" != '1' ]; then
118118
websites=`ls ${wwwroot_dir}`
119119
while :; do echo
120120
echo "Please enter one or more name for website, separate multiple website names with commas: "
121-
read -p "(Default website: `echo $websites | tr ' ' ','`) " website_name
121+
read -e -p "(Default website: `echo $websites | tr ' ' ','`) " website_name
122122
website_name=`echo ${website_name} | tr -d ' '`
123123
[ -z "${website_name}" ] && website_name="`echo $websites | tr ' ' ','`"
124124
W_tmp=0
@@ -139,16 +139,16 @@ echo "You have to backup the content:"
139139
if [ `echo ${desc_bk} | grep -e 2` ]; then
140140
> tools/iplist.txt
141141
while :; do echo
142-
read -p "Please enter the remote host ip: " remote_ip
142+
read -e -p "Please enter the remote host ip: " remote_ip
143143
[ -z "${remote_ip}" -o "${remote_ip}" == '127.0.0.1' ] && continue
144144
echo
145-
read -p "Please enter the remote host port(Default: 22) : " remote_port
145+
read -e -p "Please enter the remote host port(Default: 22) : " remote_port
146146
[ -z "${remote_port}" ] && remote_port=22
147147
echo
148-
read -p "Please enter the remote host user(Default: root) : " remote_user
148+
read -e -p "Please enter the remote host user(Default: root) : " remote_user
149149
[ -z "${remote_user}" ] && remote_user=root
150150
echo
151-
read -p "Please enter the remote host password: " remote_password
151+
read -e -p "Please enter the remote host password: " remote_password
152152
IPcode=$(echo "ibase=16;$(echo "${remote_ip}" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
153153
Portcode=$(echo "ibase=16;$(echo "${remote_port}" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
154154
PWcode=$(echo "ibase=16;$(echo "$remote_password" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
@@ -157,7 +157,7 @@ if [ `echo ${desc_bk} | grep -e 2` ]; then
157157
if [ $? -eq 0 ]; then
158158
[ -z "`grep ${remote_ip} tools/iplist.txt`" ] && echo "${remote_ip} ${remote_port} ${remote_user} $remote_password" >> tools/iplist.txt || echo "${CWARNING}${remote_ip} has been added! ${CEND}"
159159
while :; do
160-
read -p "Do you want to add more host ? [y/n]: " morehost_yn
160+
read -e -p "Do you want to add more host ? [y/n]: " morehost_yn
161161
if [[ ! ${morehost_yn} =~ ^[y,n]$ ]]; then
162162
echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
163163
else
@@ -189,7 +189,7 @@ if [ `echo ${desc_bk} | grep -e 3` ]; then
189189
echo -e "\t${CMSG}13${CEND}. ap-southeast-亚太东南 3 (吉隆坡) ${CMSG}14${CEND}. ap-southeast-亚太东南 5 (雅加达)"
190190
echo -e "\t${CMSG}15${CEND}. ap-northeast-亚太东北 1 (日本) ${CMSG}16${CEND}. ap-south-亚太南部 1 (孟买)"
191191
echo -e "\t${CMSG}17${CEND}. eu-central-欧洲中部 1 (法兰克福) ${CMSG}18${CEND}. me-east-中东东部 1 (迪拜)"
192-
read -p "Please input a number:(Default 1 press Enter) " Location
192+
read -e -p "Please input a number:(Default 1 press Enter) " Location
193193
[ -z "${Location}" ] && Location=1
194194
if [[ "${Location}" =~ ^[1-9]$|^1[0-8]$ ]]; then
195195
break
@@ -218,16 +218,16 @@ if [ `echo ${desc_bk} | grep -e 3` ]; then
218218
[ "$(./include/check_port.py ${Host} 80)" == "False" ] && Host=`echo ${Host} | sed 's@-internal@@g'`
219219
[ -e "/root/.ossutilconfig" ] && rm -f /root/.ossutilconfig
220220
while :; do echo
221-
read -p "Please enter the aliyun oss Access Key ID: " KeyID
221+
read -e -p "Please enter the aliyun oss Access Key ID: " KeyID
222222
[ -z "${KeyID}" ] && continue
223223
echo
224-
read -p "Please enter the aliyun oss Access Key Secret: " KeySecret
224+
read -e -p "Please enter the aliyun oss Access Key Secret: " KeySecret
225225
[ -z "${KeySecret}" ] && continue
226226
/usr/local/bin/ossutil ls -e ${Host} -i ${KeyID} -k ${KeySecret} >/dev/null 2>&1
227227
if [ $? -eq 0 ];then
228228
/usr/local/bin/ossutil config -e ${Host} -i ${KeyID} -k ${KeySecret} >/dev/null 2>&1
229229
while :; do echo
230-
read -p "Please enter the aliyun oss bucket: " Bucket
230+
read -e -p "Please enter the aliyun oss bucket: " Bucket
231231
/usr/local/bin/ossutil mb oss://${Bucket} >/dev/null 2>&1
232232
[ $? -eq 0 ] && { echo "${CMSG}[${Bucket}] createbucket OK${CEND}"; sed -i "s@^oss_bucket=.*@oss_bucket=${Bucket}@" ./options.conf; break; } || echo "${CWARNING}[${Bucket}] already exists, You need to use the OSS Console to create a bucket for storing.${CEND}"
233233
done
@@ -250,7 +250,7 @@ if [ `echo ${desc_bk} | grep -e 4` ]; then
250250
echo -e "\t ${CMSG}13${CEND}. na-siliconvalley-硅谷 ${CMSG}14${CEND}. na-ashburn-弗吉尼亚"
251251
echo -e "\t ${CMSG}15${CEND}. ap-bangkok-曼谷 ${CMSG}16${CEND}. eu-moscow-莫斯科"
252252
echo -e "\t ${CMSG}17${CEND}. ap-tokyo-东京"
253-
read -p "Please input a number:(Default 1 press Enter) " Location
253+
read -e -p "Please input a number:(Default 1 press Enter) " Location
254254
[ -z "${Location}" ] && Location=1
255255
if [[ "${Location}" =~ ^[1-9]$|^1[0-7]$ ]]; then
256256
break
@@ -276,16 +276,16 @@ if [ `echo ${desc_bk} | grep -e 4` ]; then
276276
[ "${Location}" == '16' ] && region='eu-moscow'
277277
[ "${Location}" == '17' ] && region='ap-tokyo'
278278
while :; do echo
279-
read -p "Please enter the Qcloud COS APPID: " APPID
279+
read -e -p "Please enter the Qcloud COS APPID: " APPID
280280
[ -z "${APPID}" ] && continue
281281
echo
282-
read -p "Please enter the Qcloud COS SecretId: " SecretId
282+
read -e -p "Please enter the Qcloud COS SecretId: " SecretId
283283
[ -z "${SecretId}" ] && continue
284284
echo
285-
read -p "Please enter the Qcloud COS SecretKey: " SecretKey
285+
read -e -p "Please enter the Qcloud COS SecretKey: " SecretKey
286286
[ -z "$SecretKey" ] && continue
287287
echo
288-
read -p "Please enter the Qcloud COS bucket: " bucket
288+
read -e -p "Please enter the Qcloud COS bucket: " bucket
289289
[ -z "${bucket}" ] && continue
290290
echo
291291
${python_install_dir}/bin/coscmd config -u ${APPID} -a ${SecretId} -s $SecretKey -r $region -b ${bucket} >/dev/null 2>&1
@@ -310,13 +310,13 @@ if [ `echo ${desc_bk} | grep -e 5` ]; then
310310
chmod +x /usr/local/bin/upx
311311
fi
312312
while :; do echo
313-
read -p "Please enter the upyun ServiceName: " ServiceName
313+
read -e -p "Please enter the upyun ServiceName: " ServiceName
314314
[ -z "${ServiceName}" ] && continue
315315
echo
316-
read -p "Please enter the upyun Operator: " Operator
316+
read -e -p "Please enter the upyun Operator: " Operator
317317
[ -z "${Operator}" ] && continue
318318
echo
319-
read -p "Please enter the upyun Password: " Password
319+
read -e -p "Please enter the upyun Password: " Password
320320
[ -z "${Password}" ] && continue
321321
echo
322322
/usr/local/bin/upx login ${ServiceName} ${Operator} ${Password} >/dev/null 2>&1
@@ -355,7 +355,7 @@ if [ `echo ${desc_bk} | grep -e 6` ]; then
355355
echo -e "\t ${CMSG} 1${CEND}. 华东 ${CMSG}2${CEND}. 华北"
356356
echo -e "\t ${CMSG} 3${CEND}. 华南 ${CMSG}4${CEND}. 北美"
357357
echo -e "\t ${CMSG} 5${CEND}. 东南亚"
358-
read -p "Please input a number:(Default 1 press Enter) " Location
358+
read -e -p "Please input a number:(Default 1 press Enter) " Location
359359
[ -z "${Location}" ] && Location=1
360360
if [[ "${Location}" =~ ^[1-5]$ ]]; then
361361
break
@@ -369,13 +369,13 @@ if [ `echo ${desc_bk} | grep -e 6` ]; then
369369
[ "${Location}" == '4' ] && zone='na0'
370370
[ "${Location}" == '5' ] && zone='as0'
371371
while :; do echo
372-
read -p "Please enter the qiniu AccessKey: " AccessKey
372+
read -e -p "Please enter the qiniu AccessKey: " AccessKey
373373
[ -z "${AccessKey}" ] && continue
374374
echo
375-
read -p "Please enter the qiniu SecretKey: " SecretKey
375+
read -e -p "Please enter the qiniu SecretKey: " SecretKey
376376
[ -z "${SecretKey}" ] && continue
377377
echo
378-
read -p "Please enter the qiniu bucket: " bucket
378+
read -e -p "Please enter the qiniu bucket: " bucket
379379
[ -z "${bucket}" ] && continue
380380
echo
381381
/usr/local/bin/qshell account ${AccessKey} ${SecretKey}

0 commit comments

Comments
 (0)