手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Linux命令之 交互式输入read

[日期:2013-03-25] 来源:Linux社区  作者:williamwang [字体:大 中 小]

5.-d 自定义定界符

输入自定义的定界符,结束输入。

[wang@localhost 桌面]$ read -d ":" -p "Enter your name :" name;echo $name

Enter your name :name:name

 

6.从标准输入中读取

[wang@localhost 桌面]$ vim testcmd.sh

#!/bin/bash

count=1

cat test.c |while read line //从test.c读取每一行并赋值给line变量

do

echo "$count:$line"

count=$[ count+1 ]

done

 


[wang@localhost 桌面]$ cat test.c

#include <stdio.h>

 

int main()

{

int a = 4;

(++a) += a;

printf("we are the best %d!\n",a);

return 0;

}

 


[wang@localhost 桌面]$ ./testcmd.sh

1:#include <stdio.h>

2:

3:int main()

4:{

5:int a = 4;

6:(++a) += a;

7:printf("we are the best %d!n",a);

8:return 0;

9:}

注意:上面的cat test.c 也可以换成ls ,ps,grep,find等等命令

linux
相关资讯       Linux 命令  Linux read命令 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款