尊龙凯时人生就是搏

Linux readÏÂÁЧÆÊÎöÓëʵÀýÑÝʾ

¡¶Linux readÏÂÁЧÆÊÎöÓëʵÀýÑÝʾ¡·

ÔÚLinuxϵͳÖÐ £¬readÏÂÁîÊÇÒ»¸öÓÃÓÚ´Ó±ê×¼ÊäÈë»òÎļþÖжÁÈ¡Êý¾ÝµÄÏÂÁî¡£Ëü¿ÉÒÔ×ÊÖúÓû§ÔÚShell¾ç±¾Öн»»¥µØ´ÓÓû§ÊäÈëÖлñÈ¡Êý¾Ý £¬²¢ÇÒ¿ÉÒÔÉúÑĵ½±äÁ¿Öй©ºóÐø´¦ÀíʹÓᣱ¾ÎĽ«¶ÔreadÏÂÁîµÄ¹¦Ð§¾ÙÐÐÆÊÎö £¬²¢ÌṩʵÀýÑÝʾÀ´×ÊÖú¶ÁÕ߸üºÃµØÃ÷È·¡£

Ò»¡¢readÏÂÁîµÄ»ù±¾Óï·¨

readÏÂÁîµÄ»ù±¾Óï·¨ÈçÏ£º

read [-options] [variable...]

µÇ¼ºó¸´ÖÆ

ÆäÖÐ £¬[]ÌåÏÖ¿ÉÑ¡Ïî £¬optionsÊÇreadÏÂÁîµÄÑ¡Ïî²ÎÊý £¬variableÊÇÓÃÓÚ´æ´¢ÊäÈëÊý¾ÝµÄ±äÁ¿Ãû¡£

¶þ¡¢readÏÂÁîµÄ³£ÓÃÑ¡Ïî

-p£ºÖ¸¶¨ÌáÐÑ·ûÐÅÏ¢ £¬ÔÚÓû§ÊäÈëÊý¾Ý֮ǰÏÔʾÌáÐÑ·û¡£

-t seconds£ºÉèÖöÁÈ¡Êý¾ÝµÄ³¬Ê±Ê±¼ä £¬µ¥Î»ÎªÃë¡£

-n count£ºÖ¸¶¨¶ÁÈ¡Êý¾ÝµÄ×Ö·ûÊý £¬µ±¶ÁÈ¡µÄ×Ö·ûÊýµÖ´ïcountʱ £¬ÖÕÖ¹¶ÁÈ¡¡£

-s£º¾²Ä¬Ä£Ê½ £¬Óû§ÊäÈë²»ÏÔʾÔÚÆÁÄ»ÉÏ¡£

-r£º½«·´Ð±¸Ü×Ö·û¿´³ÉͨË××Ö·û¿´´ý £¬²»×ªÒå¡£

Èý¡¢readÏÂÁîµÄ¹¦Ð§ÆÊÎö

ÎüÊÕÓû§ÊäÈë²¢´æ´¢µ½±äÁ¿ÖУºreadÏÂÁî¿ÉÒÔÎüÊÕÓû§µÄÊäÈë £¬²¢½«ÊäÈëµÄÊý¾Ý´æ´¢µ½Ö¸¶¨µÄ±äÁ¿ÖÐ £¬Àû±ãºóÐø¾ç±¾´¦Àí¡£

ʵÏ־籾½»»¥£ºreadÏÂÁî¿ÉÒÔÍŽáÌáÐÑÐÅÏ¢ £¬ÊµÏ־籾ÓëÓû§Ö®¼äµÄ½»»¥ £¬»ñÈ¡Óû§ÊäÈëµÄÊý¾Ý¡£

³¬Ê±´¦Àí£ºÍ¨¹ýÉèÖÃ-tÑ¡Ïî £¬¿ÉÒÔʵÏÖ³¬Ê±´¦Àí £¬ÈôÊÇÓû§ÔÚָ׼ʱ¼äÄÚûÓÐÊäÈëÊý¾Ý £¬readÏÂÁ³¬Ê±²¢¿¢Ê¡£

×Ö·û¼ÆÊý£ºÍ¨¹ý-nÑ¡Ïî £¬¿ÉÒÔ¿ØÖƶÁÈ¡µÄ×Ö·ûÊý £¬µ±µÖ´ïÖ¸¶¨×Ö·ûÊýʱ £¬readÏÂÁÖÕÖ¹¶ÁÈ¡¡£

ËÄ¡¢readÏÂÁîµÄʵÀýÑÝʾ

ÏÂÃæͨ¹ý¼¸¸öʵÀýÑÝʾreadÏÂÁîµÄÏêϸÓ÷¨£º

ʾÀý1£º»ù±¾µÄÓû§ÊäÈë

#!/bin/bash

echo "ÇëÊäÈëÄúµÄÐÕÃû£º"
read name

echo "ÄúÊäÈëµÄÐÕÃûÊÇ£º$name"

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öʾÀýÖÐ £¬Óû§Í¨¹ýreadÏÂÁîÊäÈëÐÕÃû £¬²¢½«ÊäÈëµÄÊý¾Ý´æ´¢µ½name±äÁ¿ÖÐ £¬È»ºóÊä³öµ½ÆÁÄ»ÉÏ¡£

ʾÀý2£ºÉèÖó¬Ê±Ê±¼ä

#!/bin/bash

read -t 5 -p "ÇëÊäÈëÄúµÄÄêË꣨5ÃëÄÚÊäÈ룩£º" age

if [ -z $age ]; then
    echo "ÄúδÔÚ5ÃëÄÚÊäÈëÄêËê£¬³¬Ê±¡£"
else
    echo "ÄúÊäÈëµÄÄêËêÊÇ£º$age"
fi

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öʾÀýÖÐ £¬ÉèÖÃÁË5ÃëµÄ³¬Ê±Ê±¼ä £¬ÈôÊÇÓû§ÔÚ5ÃëÄÚûÓÐÊäÈëÄêËê £¬Ôò»áÌáÐѳ¬Ê±ÐÅÏ¢¡£

ʾÀý3£º²»ÏÔʾÓû§ÊäÈë

#!/bin/bash

read -s -p "ÇëÊäÈëÄúµÄÃÜÂ룺" password

echo -e "
ÄúÊäÈëµÄÃÜÂëÊÇ£º$password"

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öʾÀýÖÐ £¬ÉèÖÃÁË-sÑ¡Ïî £¬Óû§ÊäÈëÃÜÂëʱ²»ÔÚÆÁÄ»ÉÏÏÔʾ £¬ÒÔ±£»¤ÃÜÂëÇå¾²¡£

ͨ¹ýÒÔÉÏʵÀýÑÝʾ £¬¶ÁÕß¿ÉÒÔ¸üÉîÈëµØÏàʶreadÏÂÁîµÄÓ÷¨¼°¹¦Ð§¡£ÔÚ±àдShell¾ç±¾Ê± £¬readÏÂÁîÊÇÒ»¸öºÜÊÇÊÊÓõŤ¾ß £¬¿ÉÒÔ×ÊÖúʵÏÖÓû§ÊäÈëÊý¾Ý½»»¥ £¬ÌáÉý¾ç±¾µÄ½»»¥ÐÔºÍÎÞаÐÔ¡£

×ÜÖ® £¬ÕÆÎÕreadÏÂÁîµÄʹÓÃÒªÁì £¬¹ØÓÚLinuxϵͳÓû§À´ËµÊÇÊ®·ÖÖ÷ÒªµÄ¡£Ï£Íû±¾ÎĶԶÁÕßÓÐËù×ÊÖú £¬Ð»Ð»ÔĶÁ£¡

ÒÔÉϾÍÊÇLinux readÏÂÁЧÆÊÎöÓëʵÀýÑÝʾµÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是搏ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是搏ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是搏

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ