【shell】Here文档自动生成Makefile
来源:互联网 发布:淘宝上买车保险便宜吗 编辑:程序博客网 时间:2024/05/18 05:44
在shell脚本程序中向一条命令传递输入的一种特殊方法就是使用Here文档,它允许一条命令在获得输入数据时就好像是在读取一个文件或者键盘一样,实际上是从脚本程序中得到输入数据。
here文档就是一段具有特殊目的的代码块,它使用I/O重定向的方式将一个命令序列传递到一个交互程序或者命令中。
格式
[命令] << [标识符]命令序列......[标识符]
应用
将命令序列传到另一个命令
#/bin/bashcat << ENDhellohello worldNice to meet youEND
end标识符限定了here文档的起始和结束位置。此文档实现了将语句传递cat命令。执行shell脚本的结果为:
[lzk@localhost 33_class_3_26_shell]$ ./test.sh hellohello worldNice to meet you
将命令序列输入进一个文件(生产Makefile)
#!/bin/bashSRC=$(echo *.c)BIN=testfunCC=gcccat << EOF > Makefile ##输出重定向到Makefile文件${BIN}:$SRC $CC -o \$@ \$^.PHONY:cleanclean: rm -f $BINEOF
结果生产Makefile文件:
[lzk@localhost fun]$ cat Makefile testfun:test.c gcc -o $@ $^.PHONY:cleanclean: rm -f testfun
将命令序列传递给交互式程序
将命令序列传递给ed编辑器。
[[ $# -ne 1 ]] && { printf "Please input `basename $0` [filename]" exit -1}ed $1<< END ### 打开文件i hello world #输入Nice to meet you #输入. ## 保存退出wqEND
结果:
[lzk@localhost 33_class_3_26_shell]$ ./test.sh 1.txt029[lzk@localhost 33_class_3_26_shell]$ ls1.txt shell test.sh[lzk@localhost 33_class_3_26_shell]$ cat 1.txt hello worldNice to meet you
将命令序列传递给vim编辑器:
[[ $# -ne 1 ]] && { printf "Please input `basename $0` [filename]" exit -1}vim $1<< ENDihello world ssssNice to meet you^[:wqEND
利用vim编辑器退出保存时需要ESC键,如何输入ESC键呢?
模拟ESC键:按住ctrl+v,再按esc,就会输入一个“^[”,就是ESC键。
结果:
[lzk@localhost 33_class_3_26_shell]$ ./test.sh 1.txt Vim: Warning: Input is not from a terminal //vim报出警告:不是从终端输入[lzk@localhost 33_class_3_26_shell]$ cat 1.txt hello world ssssNice to meet you
使用here文档控制mysql
mysql<< ENDshow databases;use mysql;select * from userEND
结果:
[root@localhost 33_class_3_26_shell]# ./test.sh Databaseinformation_schemamysqltestHost User Password Select_priv Insert_priv Update_priv Delete_priv Create_priv Drop_priv Reload_priv Shutdown_priv Process_priv File_priv Grant_priv References_priv Index_priv Alter_priv Show_db_priv Super_priv Create_tmp_table_priv Lock_tables_priv Execute_priv Repl_slave_priv Repl_client_priv Create_view_priv Show_view_priv Create_routine_priv Alter_routine_priv Create_user_priv Event_priv Trigger_priv ssl_type ssl_cipher x509_issuer x509_subject max_questions max_updates max_connectionsmax_user_connectionslocalhost root Y Y Y Y Y Y YY Y Y Y Y Y Y Y Y Y YY Y Y Y Y Y Y Y Y Y 00 0 0localhost.localdomain root Y Y Y Y Y YY Y Y Y Y Y Y Y Y Y YY Y Y Y Y Y Y Y Y Y Y0 0 0 0127.0.0.1 root Y Y Y Y Y Y YY Y Y Y Y Y Y Y Y Y YY Y Y Y Y Y Y Y Y Y 00 0 0localhost N N N N N N NN N N N N N N N N N NN N N N N N N N N N 00 0 0localhost.localdomain N N N N N NN N N N N N N N N N NN N N N N N N N N N N0 0 0 0
0 0
- 【shell】Here文档自动生成Makefile
- shell here 文档 || #!
- Shell中的here文档
- shell编程:here文档
- makefile + shell脚本自动生成动态库
- 【shell】嵌入文档Here Documents
- Shell 中的 here 文档详解
- linux shell 下here document 文档
- shell [ here 文档的用法初步 ]
- here文档 自动进行 FTP文件传输
- makefile 自动生成makefile 步骤
- ACE自动生成makefile
- 自动生成makefile
- automake自动生成makefile
- makefile的自动生成
- makefile----自动生成依赖性
- 自动生成Makefile
- 怎样自动生成makefile
- Android——JsBridge实战(二)
- js身份证正则表达式验证
- 文章标题
- web/jsp实现session登录注销 springMVC
- Altium Designer 16 导线、焊盘报错 Clearance Constraint、Short-Circuit
- 【shell】Here文档自动生成Makefile
- 文章标题
- jsp页面传递date到java报错
- android 隐藏虚拟按键
- 强哥收藏的Android开源库集合【UI效果篇】
- 数据结构——后缀树
- ES 5.3 集群安装
- Spring Boot 热部署之spring-boot-devtools
- Java十进制转化成二进制方法