read

从标准输入(或从文件)中读取一行,并将单词分配给变量名称

语法

  read [-ers] [-a aname] [-p prompt] [-t timeout]
          [-n nchars] [-d delim] [name...]

选项



   -a aname
             后跟一个变量,该变量会被认为是个数组,然后给其赋值,默认是以空格为分割符

   -d delim
             后面跟一个标志符,其实只有其后的第一个字符有用,作为结束的标志

   -e        如果标准输入来自终端,则使用readline来获取行

   -n nchars
             后跟一个数字,定义输入文本的长度,很实用。

   -p prompt
             后面跟提示信息,即在输入前打印提示信息。

   -r        屏蔽,如果没有该选项,则作为一个转义字符,有的话 就是个正常的字符了。

   -s        安静模式,在输入字符时不再屏幕上显示,例如login时输入密码。

   -t timeout
            后面跟秒数,定义输入字符的等待时间。

   -u fd     后面跟fd,从文件描述符中读入,该文件描述符可以是exec新开启的。


这是一个内置的BASH shell。

实例

#!/bin/bash
read var_year 
echo "The year is: $var_year"

echo -n "Enter your name and press [ENTER]: " 
read var_name
echo "Your name is: $var_name"

  1. 提示“请输入姓名”并等待30秒,输入值保存到变量name中
    $ read -t 30 -p "please input your name: " name
    please input your name: tank

    $ echo $name
    tank

read 命令实例:

linux命令:read VAR1 VAR2 VAR3 < <(echo aa bb cc); echo $VAR2 $VAR2 echo cc); bb aa <(echo < VAR3 VAR2 VAR1 read read VAR1 VAR2 VAR3 < <(echo aa bb cc); echo $VAR2rootopen.com
linux命令:read VAR1 VAR2 VAR3 < <(echo aa bb cc); echo $VAR2 $VAR2 echo cc); bb aa <(echo < VAR3 VAR2 VAR1 read read VAR1 VAR2 VAR3 < <(echo aa bb cc); echo $VAR2rootopen.com
2018-01-19 20:40:48

linux命令:readom dev=/dev/scd0 f=/path/to/image.iso f=/path/to/image.iso dev=/dev/scd0 readom readom dev=/dev/scd0 f=/path/to/image.isorootopen.com
linux命令:readom dev=/dev/scd0 f=/path/to/image.iso f=/path/to/image.iso dev=/dev/scd0 readom readom dev=/dev/scd0 f=/path/to/image.isorootopen.com
2018-03-06 20:00:48

linux命令:read -p 'Username: ' u;sudo -H -u $u xauth add $(xauth list|grep :$(echo ${DISPLAY: -4:2}));sudo su - $u $u - su -4:2}));sudo ${DISPLAY: :$(echo list|grep $(xauth add xauth $u -u -H u;sudo ' 'Username: -p read read -p 'Username: ' u;sudo -H -u $u xauth add $(xauth list|grep :$(echo ${DISPLAY: -4:2}));sudo su - $urootopen.com
linux命令:read -p 'Username: ' u;sudo -H -u $u xauth add $(xauth list|grep :$(echo ${DISPLAY: -4:2}));sudo su - $u $u - su -4:2}));sudo ${DISPLAY: :$(echo list|grep $(xauth add xauth $u -u -H u;sudo ' 'Username: -p read read -p 'Username: ' u;sudo -H -u $u xauth add $(xauth list|grep :$(echo ${DISPLAY: -4:2}));sudo su - $urootopen.com
2018-04-22 21:35:48

linux命令:read -p "Which station? "; mplayer --reallyquiet -vo none -ao sdl http://somafm.com/startstream=${REPLY}.pls http://somafm.com/startstream=${REPLY}.pls sdl -ao none -vo --reallyquiet mplayer "; station? "Which -p read read -p "Which station? "; mplayer --reallyquiet -vo none -ao sdl http://somafm.com/startstream=${REPLY}.plsrootopen.com
linux命令:read -p "Which station? "; mplayer --reallyquiet -vo none -ao sdl http://somafm.com/startstream=${REPLY}.pls http://somafm.com/startstream=${REPLY}.pls sdl -ao none -vo --reallyquiet mplayer "; station? "Which -p read read -p "Which station? "; mplayer --reallyquiet -vo none -ao sdl http://somafm.com/startstream=${REPLY}.plsrootopen.com
2018-04-03 08:46:48

linux命令:readlink -f /proc/<pid>/cmdline /proc/<pid>/cmdline -f readlink readlink -f /proc/<pid>/cmdlinerootopen.com
linux命令:readlink -f /proc/<pid>/cmdline /proc/<pid>/cmdline -f readlink readlink -f /proc/<pid>/cmdlinerootopen.com
2018-02-28 17:36:48

linux命令:readlink -f ../super/symlink_bon/ahoy ../super/symlink_bon/ahoy -f readlink readlink -f ../super/symlink_bon/ahoyrootopen.com
linux命令:readlink -f ../super/symlink_bon/ahoy ../super/symlink_bon/ahoy -f readlink readlink -f ../super/symlink_bon/ahoyrootopen.com
2018-04-28 22:57:48

linux命令:read -sn 1 -p "Press any key to continue..." continue..." to key any "Press -p 1 -sn read read -sn 1 -p "Press any key to continue..."rootopen.com
linux命令:read -sn 1 -p "Press any key to continue..." continue..." to key any "Press -p 1 -sn read read -sn 1 -p "Press any key to continue..."rootopen.com
2017-12-29 02:04:48

linux命令:read -sn 1 -p 'Press any key to continue...';echo continue...';echo to key any 'Press -p 1 -sn read read -sn 1 -p 'Press any key to continue...';echorootopen.com
linux命令:read -sn 1 -p 'Press any key to continue...';echo continue...';echo to key any 'Press -p 1 -sn read read -sn 1 -p 'Press any key to continue...';echorootopen.com
2018-02-16 08:02:48

linux命令:read enterKey enterKey read read enterKeyrootopen.com
linux命令:read enterKey enterKey read read enterKeyrootopen.com
2018-05-13 14:22:48

linux命令:read -p "Press enter to continue.." continue.." to enter "Press -p read read -p "Press enter to continue.."rootopen.com
linux命令:read -p "Press enter to continue.." continue.." to enter "Press -p read read -p "Press enter to continue.."rootopen.com
2018-03-11 22:46:48

linux命令:read -sn1 -p "Press any key to continue..."; echo echo continue..."; to key any "Press -p -sn1 read read -sn1 -p "Press any key to continue..."; echorootopen.com
linux命令:read -sn1 -p "Press any key to continue..."; echo echo continue..."; to key any "Press -p -sn1 read read -sn1 -p "Press any key to continue..."; echorootopen.com
2018-01-11 14:04:48

linux命令:read -p "enter url:" a ; w3m -dump $a > /dev/shm/e1q ; less /dev/shm/e1q ; read -p "save file as text (y/n)?" b ; if [ $b = "y" ] ; then read -p "enter path with filename:" c && touch $(eval echo "$c") ; mv /dev/shm/e1q $(eval echo "$c") ; fi ; echo DONE DONE echo ; fi ; "$c") echo $(eval /dev/shm/e1q mv ; "$c") echo $(eval touch && c filename:" with path "enter -p read then ; ] "y" = $b [ if ; b (y/n)?" text as file "save -p read ; /dev/shm/e1q less ; /dev/shm/e1q > $a -dump w3m ; a url:" "enter -p read read -p "enter url:" a ; w3m -dump $a > /dev/shm/e1q ; less /dev/shm/e1q ; read -p "save file as text (y/n)?" b ; if [ $b = "y" ] ; then read -p "enter path with filename:" c && touch $(eval echo "$c") ; mv /dev/shm/e1q $(eval echo "$c") ; fi ; echo DONErootopen.com
linux命令:read -p "enter url:" a ; w3m -dump $a > /dev/shm/e1q ; less /dev/shm/e1q ; read -p "save file as text (y/n)?" b ; if [ $b = "y" ] ; then read -p "enter path with filename:" c && touch $(eval echo "$c") ; mv /dev/shm/e1q $(eval echo "$c") ; fi ; echo DONE DONE echo ; fi ; "$c") echo $(eval /dev/shm/e1q mv ; "$c") echo $(eval touch && c filename:" with path "enter -p read then ; ] "y" = $b [ if ; b (y/n)?" text as file "save -p read ; /dev/shm/e1q less ; /dev/shm/e1q > $a -dump w3m ; a url:" "enter -p read read -p "enter url:" a ; w3m -dump $a > /dev/shm/e1q ; less /dev/shm/e1q ; read -p "save file as text (y/n)?" b ; if [ $b = "y" ] ; then read -p "enter path with filename:" c && touch $(eval echo "$c") ; mv /dev/shm/e1q $(eval echo "$c") ; fi ; echo DONErootopen.com
2018-02-18 00:46:48

linux命令:read -e -s -p "Password: " password password " "Password: -p -s -e read read -e -s -p "Password: " passwordrootopen.com
linux命令:read -e -s -p "Password: " password password " "Password: -p -s -e read read -e -s -p "Password: " passwordrootopen.com
2018-02-25 08:08:48

linux命令:read -a A<<<".*.**..*....*** 8 9 5 10 6 0 2 11 7 4";for C in `date +"%H%M"|fold -w1`;do echo "${A:${A[C+1]}:4}";done "${A:${A[C+1]}:4}";done echo -w1`;do +"%H%M"|fold `date in C 4";for 7 11 2 0 6 10 5 9 8 A<<<".*.**..*....*** -a read read -a A<<<".*.**..*....*** 8 9 5 10 6 0 2 11 7 4";for C in `date +"%H%M"|fold -w1`;do echo "${A:${A[C+1]}:4}";donerootopen.com
linux命令:read -a A<<<".*.**..*....*** 8 9 5 10 6 0 2 11 7 4";for C in `date +"%H%M"|fold -w1`;do echo "${A:${A[C+1]}:4}";done "${A:${A[C+1]}:4}";done echo -w1`;do +"%H%M"|fold `date in C 4";for 7 11 2 0 6 10 5 9 8 A<<<".*.**..*....*** -a read read -a A<<<".*.**..*....*** 8 9 5 10 6 0 2 11 7 4";for C in `date +"%H%M"|fold -w1`;do echo "${A:${A[C+1]}:4}";donerootopen.com
2018-05-15 11:19:48

linux命令:read -a ARR <<<'world domination now!'; echo ${ARR[2]}; ${ARR[2]}; echo now!'; domination <<<'world ARR -a read read -a ARR <<<'world domination now!'; echo ${ARR[2]};rootopen.com
linux命令:read -a ARR <<<'world domination now!'; echo ${ARR[2]}; ${ARR[2]}; echo now!'; domination <<<'world ARR -a read read -a ARR <<<'world domination now!'; echo ${ARR[2]};rootopen.com
2018-02-07 01:11:48

linux命令:read -a A <<<"8 9 5 10 6 0 3 11 7 4";B='.*.**..*....***';for C in $(date +"%H%M"|fold -w1);do echo "${B:${A[C]}:4}";done "${B:${A[C]}:4}";done echo -w1);do +"%H%M"|fold $(date in C 4";B='.*.**..*....***';for 7 11 3 0 6 10 5 9 <<<"8 A -a read read -a A <<<"8 9 5 10 6 0 3 11 7 4";B='.*.**..*....***';for C in $(date +"%H%M"|fold -w1);do echo "${B:${A[C]}:4}";donerootopen.com
linux命令:read -a A <<<"8 9 5 10 6 0 3 11 7 4";B='.*.**..*....***';for C in $(date +"%H%M"|fold -w1);do echo "${B:${A[C]}:4}";done "${B:${A[C]}:4}";done echo -w1);do +"%H%M"|fold $(date in C 4";B='.*.**..*....***';for 7 11 3 0 6 10 5 9 <<<"8 A -a read read -a A <<<"8 9 5 10 6 0 3 11 7 4";B='.*.**..*....***';for C in $(date +"%H%M"|fold -w1);do echo "${B:${A[C]}:4}";donerootopen.com
2018-01-09 13:05:48

linux命令:readlink -e /bin/ls /bin/ls -e readlink readlink -e /bin/lsrootopen.com
linux命令:readlink -e /bin/ls /bin/ls -e readlink readlink -e /bin/lsrootopen.com
2018-03-14 08:32:48

linux命令:readlink -f /proc/$$/exe /proc/$$/exe -f readlink readlink -f /proc/$$/exerootopen.com
linux命令:readlink -f /proc/$$/exe /proc/$$/exe -f readlink readlink -f /proc/$$/exerootopen.com
2018-01-06 19:53:48

linux命令:readlink -f myfile.txt myfile.txt -f readlink readlink -f myfile.txtrootopen.com
linux命令:readlink -f myfile.txt myfile.txt -f readlink readlink -f myfile.txtrootopen.com
2018-06-03 14:07:48

linux命令:readlink /proc/self/cwd /proc/self/cwd readlink readlink /proc/self/cwdrootopen.com
linux命令:readlink /proc/self/cwd /proc/self/cwd readlink readlink /proc/self/cwdrootopen.com
2018-04-28 11:54:48

linux命令:read -t 0.1 -N 255 255 -N 0.1 -t read read -t 0.1 -N 255rootopen.com
linux命令:read -t 0.1 -N 255 255 -N 0.1 -t read read -t 0.1 -N 255rootopen.com
2018-05-18 09:33:48

linux命令:read -s -p"Password: " USER_PASSWORD_VARIABLE; echo echo USER_PASSWORD_VARIABLE; " -p"Password: -s read read -s -p"Password: " USER_PASSWORD_VARIABLE; echorootopen.com
linux命令:read -s -p"Password: " USER_PASSWORD_VARIABLE; echo echo USER_PASSWORD_VARIABLE; " -p"Password: -s read read -s -p"Password: " USER_PASSWORD_VARIABLE; echorootopen.com
2017-12-27 10:07:48

linux命令:read VAR1 VAR2 VAR3 <<< aa bb cc; echo $VAR2 $VAR2 echo cc; bb aa <<< VAR3 VAR2 VAR1 read read VAR1 VAR2 VAR3 <<< aa bb cc; echo $VAR2rootopen.com
linux命令:read VAR1 VAR2 VAR3 <<< aa bb cc; echo $VAR2 $VAR2 echo cc; bb aa <<< VAR3 VAR2 VAR1 read read VAR1 VAR2 VAR3 <<< aa bb cc; echo $VAR2rootopen.com
2018-02-19 23:38:48

linux命令:read day month year <<< $(date +'%d %m %y') %y') %m +'%d $(date <<< year month day read read day month year <<< $(date +'%d %m %y')rootopen.com
linux命令:read day month year <<< $(date +'%d %m %y') %y') %m +'%d $(date <<< year month day read read day month year <<< $(date +'%d %m %y')rootopen.com
2018-03-01 07:49:48

linux命令:read day month year < <(date +'%d %m %y') %y') %m +'%d <(date < year month day read read day month year < <(date +'%d %m %y')rootopen.com
linux命令:read day month year < <(date +'%d %m %y') %y') %m +'%d <(date < year month day read read day month year < <(date +'%d %m %y')rootopen.com
2018-02-01 03:09:48

linux命令:read -ra words <<< "<sentence>" && echo "${words[@]^}" "${words[@]^}" echo && "<sentence>" <<< words -ra read read -ra words <<< "<sentence>" && echo "${words[@]^}"rootopen.com
linux命令:read -ra words <<< "<sentence>" && echo "${words[@]^}" "${words[@]^}" echo && "<sentence>" <<< words -ra read read -ra words <<< "<sentence>" && echo "${words[@]^}"rootopen.com
2018-03-23 22:16:48

linux命令:readlink -f <file> <file> -f readlink readlink -f <file>rootopen.com
linux命令:readlink -f <file> <file> -f readlink readlink -f <file>rootopen.com
2018-02-11 23:01:48

linux命令:read -d "" "" -d read read -d ""rootopen.com
linux命令:read -d "" "" -d read read -d ""rootopen.com
2018-05-30 06:24:48

linux命令:read c; while [ -n "$c" ]; do clear; echo -e "$c = "$(echo "$c" |bc -l)"\n"; read c; done done c; read -l)"\n"; |bc "$c" "$(echo = "$c -e echo clear; do ]; "$c" -n [ while c; read read c; while [ -n "$c" ]; do clear; echo -e "$c = "$(echo "$c" |bc -l)"\n"; read c; donerootopen.com
linux命令:read c; while [ -n "$c" ]; do clear; echo -e "$c = "$(echo "$c" |bc -l)"\n"; read c; done done c; read -l)"\n"; |bc "$c" "$(echo = "$c -e echo clear; do ]; "$c" -n [ while c; read read c; while [ -n "$c" ]; do clear; echo -e "$c = "$(echo "$c" |bc -l)"\n"; read c; donerootopen.com
2018-04-15 20:38:48

linux命令:read -s pass; echo $pass | md5sum | base64 | cut -c -16 -16 -c cut | base64 | md5sum | $pass echo pass; -s read read -s pass; echo $pass | md5sum | base64 | cut -c -16rootopen.com
linux命令:read -s pass; echo $pass | md5sum | base64 | cut -c -16 -16 -c cut | base64 | md5sum | $pass echo pass; -s read read -s pass; echo $pass | md5sum | base64 | cut -c -16rootopen.com
2018-04-19 02:09:48

linux命令:read -s PASS; echo $PASS | convert sensitive.jpg -encipher - -depth 8 png24:hidden.png png24:hidden.png 8 -depth - -encipher sensitive.jpg convert | $PASS echo PASS; -s read read -s PASS; echo $PASS | convert sensitive.jpg -encipher - -depth 8 png24:hidden.pngrootopen.com
linux命令:read -s PASS; echo $PASS | convert sensitive.jpg -encipher - -depth 8 png24:hidden.png png24:hidden.png 8 -depth - -encipher sensitive.jpg convert | $PASS echo PASS; -s read read -s PASS; echo $PASS | convert sensitive.jpg -encipher - -depth 8 png24:hidden.pngrootopen.com
2018-01-28 20:57:48

linux命令:read -p "Question that you want an answer to?" yn yn to?" answer an want you that "Question -p read read -p "Question that you want an answer to?" ynrootopen.com
linux命令:read -p "Question that you want an answer to?" yn yn to?" answer an want you that "Question -p read read -p "Question that you want an answer to?" ynrootopen.com
2018-01-20 01:58:48

linux命令:read -s p && echo -n $p | md5sum;p= md5sum;p= | $p -n echo && p -s read read -s p && echo -n $p | md5sum;p=rootopen.com
linux命令:read -s p && echo -n $p | md5sum;p= md5sum;p= | $p -n echo && p -s read read -s p && echo -n $p | md5sum;p=rootopen.com
2018-03-26 17:10:48

linux命令:read && ffmpeg -y -r 1 -t 3 -f video4linux2 -vframes 1 -s sxga -i /dev/video0 ~/webcam-$(date +%m_%d_%Y_%H_%M).jpeg +%m_%d_%Y_%H_%M).jpeg ~/webcam-$(date /dev/video0 -i sxga -s 1 -vframes video4linux2 -f 3 -t 1 -r -y ffmpeg && read read && ffmpeg -y -r 1 -t 3 -f video4linux2 -vframes 1 -s sxga -i /dev/video0 ~/webcam-$(date +%m_%d_%Y_%H_%M).jpegrootopen.com
linux命令:read && ffmpeg -y -r 1 -t 3 -f video4linux2 -vframes 1 -s sxga -i /dev/video0 ~/webcam-$(date +%m_%d_%Y_%H_%M).jpeg +%m_%d_%Y_%H_%M).jpeg ~/webcam-$(date /dev/video0 -i sxga -s 1 -vframes video4linux2 -f 3 -t 1 -r -y ffmpeg && read read && ffmpeg -y -r 1 -t 3 -f video4linux2 -vframes 1 -s sxga -i /dev/video0 ~/webcam-$(date +%m_%d_%Y_%H_%M).jpegrootopen.com
2018-03-13 17:07:48

linux命令:readlink -f /proc/$pid/exe /proc/$pid/exe -f readlink readlink -f /proc/$pid/exerootopen.com
linux命令:readlink -f /proc/$pid/exe /proc/$pid/exe -f readlink readlink -f /proc/$pid/exerootopen.com
2018-03-17 10:19:48

linux命令:readlink -fn foo | xsel -ib -ib xsel | foo -fn readlink readlink -fn foo | xsel -ibrootopen.com
linux命令:readlink -fn foo | xsel -ib -ib xsel | foo -fn readlink readlink -fn foo | xsel -ibrootopen.com
2018-03-31 13:46:48

linux命令:read -p 'Script: ' S && C=$S.crypt H='eval "$((dd if=$0 bs=1 skip=//|gpg -d)2>/dev/null)"; exit;' && gpg -c<$S|cat >$C <(echo $H|sed s://:$(echo "$H"|wc -c):) - <(chmod +x $C) $C) +x <(chmod - -c):) "$H"|wc s://:$(echo $H|sed <(echo >$C -c<$S|cat gpg && exit;' -d)2>/dev/null)"; skip=//|gpg bs=1 if=$0 "$((dd H='eval C=$S.crypt && S ' 'Script: -p read read -p 'Script: ' S && C=$S.crypt H='eval "$((dd if=$0 bs=1 skip=//|gpg -d)2>/dev/null)"; exit;' && gpg -c<$S|cat >$C <(echo $H|sed s://:$(echo "$H"|wc -c):) - <(chmod +x $C)rootopen.com
linux命令:read -p 'Script: ' S && C=$S.crypt H='eval "$((dd if=$0 bs=1 skip=//|gpg -d)2>/dev/null)"; exit;' && gpg -c<$S|cat >$C <(echo $H|sed s://:$(echo "$H"|wc -c):) - <(chmod +x $C) $C) +x <(chmod - -c):) "$H"|wc s://:$(echo $H|sed <(echo >$C -c<$S|cat gpg && exit;' -d)2>/dev/null)"; skip=//|gpg bs=1 if=$0 "$((dd H='eval C=$S.crypt && S ' 'Script: -p read read -p 'Script: ' S && C=$S.crypt H='eval "$((dd if=$0 bs=1 skip=//|gpg -d)2>/dev/null)"; exit;' && gpg -c<$S|cat >$C <(echo $H|sed s://:$(echo "$H"|wc -c):) - <(chmod +x $C)rootopen.com
2018-03-12 18:33:48

linux命令:read -N1 -N1 read read -N1rootopen.com
linux命令:read -N1 -N1 read read -N1rootopen.com
2018-01-18 05:11:48

linux命令:read -p "Please enter the 4chan url: "|egrep '//i.4cdn.org/[a-z0-9]+/src/([0-9]*).(jpg|png|gif)' - -o|nl -s https:|cut -c7-|uniq|wget -nc -i - --random-wait --random-wait - -i -nc -c7-|uniq|wget https:|cut -s -o|nl - '//i.4cdn.org/[a-z0-9]+/src/([0-9]*).(jpg|png|gif)' "|egrep url: 4chan the enter "Please -p read read -p "Please enter the 4chan url: "|egrep '//i.4cdn.org/[a-z0-9]+/src/([0-9]*).(jpg|png|gif)' - -o|nl -s https:|cut -c7-|uniq|wget -nc -i - --random-waitrootopen.com
linux命令:read -p "Please enter the 4chan url: "|egrep '//i.4cdn.org/[a-z0-9]+/src/([0-9]*).(jpg|png|gif)' - -o|nl -s https:|cut -c7-|uniq|wget -nc -i - --random-wait --random-wait - -i -nc -c7-|uniq|wget https:|cut -s -o|nl - '//i.4cdn.org/[a-z0-9]+/src/([0-9]*).(jpg|png|gif)' "|egrep url: 4chan the enter "Please -p read read -p "Please enter the 4chan url: "|egrep '//i.4cdn.org/[a-z0-9]+/src/([0-9]*).(jpg|png|gif)' - -o|nl -s https:|cut -c7-|uniq|wget -nc -i - --random-waitrootopen.com
2018-02-02 15:26:48

linux命令:read -d ^D ^D -d read read -d ^Drootopen.com
linux命令:read -d ^D ^D -d read read -d ^Drootopen.com
2018-02-28 05:36:48

linux命令:read -p "> " URL; echo -e "> `echo $URL | sed 's|%|\\\\x|g'`" 's|%|\\\\x|g'`" sed | $URL `echo "> -e echo URL; " "> -p read read -p "> " URL; echo -e "> `echo $URL | sed 's|%|\\\\x|g'`"rootopen.com
linux命令:read -p "> " URL; echo -e "> `echo $URL | sed 's|%|\\\\x|g'`" 's|%|\\\\x|g'`" sed | $URL `echo "> -e echo URL; " "> -p read read -p "> " URL; echo -e "> `echo $URL | sed 's|%|\\\\x|g'`"rootopen.com
2018-04-23 07:35:48

Linux的Bash命令行(A-Z排序)