×ðÁú¿­Ê±

Linux readÏÂÁîµÄÍêÈ«ÏÈÈݺÍʹÓÃÒªÁì

ÎÊÌ⣺Linux readÏÂÁîÏê½â¼°Ó÷¨Ö¸ÄÏ

ÔÚLinuxϵͳÖÐ £¬readÏÂÁîÊÇÒ»¸ö·Ç¾­³£ÓõÄÏÂÁî £¬ÓÃÓÚ´Ó±ê×¼ÊäÈë»òÎļþÖжÁÈ¡Êý¾Ý £¬²¢½«Êý¾Ý¸³Öµ¸ø±äÁ¿¡£ËüµÄÓ÷¨¼òÆÓÎÞа £¬¿ÉÒÔ×ÊÖúÓû§ÊµÏÖÖÖÖÖ½»»¥Ê½µÄ²Ù×÷¡£±¾ÎĽ«ÏêϸÏÈÈÝreadÏÂÁîµÄÓï·¨¡¢²ÎÊýÒÔ¼°ÏêϸµÄ´úÂëʾÀý £¬×ÊÖú¶ÁÕ߸üºÃµØÃ÷È·ºÍÕÆÎÕ¸ÃÏÂÁî¡£

Ò»¡¢readÏÂÁîÓï·¨¼°²ÎÊý

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

read [Ñ¡Ïî] [±äÁ¿Ãû]

µÇ¼ºó¸´ÖÆ

³£ÓõÄÑ¡Ïî°üÀ¨£º

-p prompt£ºÖ¸¶¨¶ÁÈ¡Êý¾ÝʱµÄÌáÐÑ·û¡£

-r£º±ÜÃâreadÏÂÁî¶Ô·´Ð±¸Ü×Ö·û¾ÙÐÐתÒå¡£

-t timeout£ºÉèÖó¬Ê±Ê±¼ä £¬µ¥Î»ÎªÃë¡£

-n nchars£ºÖ¸¶¨¶ÁÈ¡µÄ×Ö·ûÊý¡£

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

-u fd£º´ÓÎļþÐÎò·ûfdÖжÁÈ¡Êý¾Ý¡£

¶þ¡¢readÏÂÁîʾÀý

¶ÁÈ¡Óû§ÊäÈë²¢½«Æ丳ֵ¸ø±äÁ¿£º

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

µÇ¼ºó¸´ÖÆ

ÔËÐÐÉÏÊö´úÂë»áÌáÐÑÓû§ÊäÈëÐÕÃû £¬²¢½«ÊäÈëµÄÖµ¸³¸ø±äÁ¿name £¬È»ºóÊä³öÐÕÃûµÄÖµ¡£

¶ÁÈ¡¶à¸öÊý¾Ý²¢»®·Ö¸³Öµ¸ø¶à¸ö±äÁ¿£º

read -p "ÇëÊäÈëÄúµÄÐÕÃûºÍÄêË꣺" name age
echo "ÄúµÄÐÕÃûÊÇ£º$name£¬ÄêËêÊÇ£º$age"

µÇ¼ºó¸´ÖÆ

Õâ¶Î´úÂë»áÌáÐÑÓû§ÊäÈëÐÕÃûºÍÄêËê £¬È»ºó»®·Ö½«ÊäÈëµÄÖµ¸³¸ø±äÁ¿nameºÍage £¬²¢Êä³öËüÃǵÄÖµ¡£

ʹÓÃÑ­»·¶ÁÈ¡¶àÐÐÊý¾Ý£º

echo "ÇëÊäÈëÈý¸öϲ»¶µÄË®¹û£º"
count=0
while [ $count -lt 3 ]
do
    read fruit
    echo "Äúϲ»¶µÄË®¹ûÖ®Ò»ÊÇ£º$fruit"
    ((count++))
done

µÇ¼ºó¸´ÖÆ

Õâ¶Î´úÂë»áÑ­»·ÌáÐÑÓû§ÊäÈëÈýÖÖϲ»¶µÄË®¹û £¬²¢ÒÀ´ÎÊä³öÓû§ÊäÈëµÄÿÖÖË®¹û¡£

ÉèÖó¬Ê±Ê±¼ä£º

if read -t 5 -p "ÇëÊäÈëÄúµÄÃÜÂ룺" password
then
    echo "ÃÜÂëÊäÈëÀֳɣº$password"
else
    echo "ÃÜÂëÊäÈ볬ʱ"
fi

µÇ¼ºó¸´ÖÆ

Õâ¶Î´úÂë»áÔÚ5ÃëÄÚÆÚ´ýÓû§ÊäÈëÃÜÂë £¬ÈôÊdz¬Ê±ÔòÊä³ö¡°ÃÜÂëÊäÈ볬ʱ¡± £¬²»È»Êä³öÓû§ÊäÈëµÄÃÜÂë¡£

Èý¡¢×ܽá

ͨ¹ýÒÔÉÏʾÀý £¬¶ÁÕß¿ÉÒÔÔ½·¢ÉîÈëµØÃ÷È·LinuxÖÐreadÏÂÁîµÄÓ÷¨¼°ÎÞаÐÔ¡£readÏÂÁîÔÚ±àд¾ç±¾¡¢ÊµÏÖ½»»¥Ê½¹¦Ð§Ê±¶¼ºÜÊÇÓÐÓà £¬Äܹ»¼ò»¯Óû§ÊäÈëÊý¾ÝµÄ²Ù×÷Á÷³Ì¡£Ï£Íû±¾ÎÄÄܹ»×ÊÖú¶ÁÕ߸üºÃµØÕÆÎÕreadÏÂÁî £¬²¢ÔÚÏÖʵӦÓÃÖÐÊ©Õ¹Æä×÷Óá£

ÒÔÉϾÍÊÇLinux readÏÂÁîµÄÍêÈ«ÏÈÈݺÍʹÓÃÒªÁìµÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±

13452372176

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

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

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