shell之read的使用

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了shell之read的使用相关的知识,希望对你有一定的参考价值。

    read命令用于接收键盘的标准输入以及其它文件的输入,得到输入后,read命令会将数据放到一个标准变量中。

示例 1:

#!/bin/bash

read -s -p  "Enter you password: " password            #-s:不显示输入,-p:在read命令行指

echo "Hello,your password is $password"                定一个提示


示例 2:

#!/bin/bash

echo -n "Enter your name: "

read name                                              #从键盘输入

echo "Hello! $name"


#!/bin/bash

read -t 5 -p "Enter your name: " name                  #-t:设定时间限制

echo "This is $name"


示例 3:读行

#!/bin/bash

file=/etc/fstab

i=1

cat $file | while read line

do

  echo $i###$line

  ((i++))

done


本文出自 “一万年太久,只争朝夕” 博客,请务必保留此出处http://zengwj1949.blog.51cto.com/10747365/1924434

以上是关于shell之read的使用的主要内容,如果未能解决你的问题,请参考以下文章

Shell编程之二——read ,array,

Linux_Shell脚本编程之read读取控制台输入

shell脚本之函数的定义及使用

大数据之Shell:read读取控制台输入

shell简单使用变量之二

shell之读取文件