shell之echo and printf
#!/bin/sh
_________echo___________
#read name
#echo "$name It is a test" #read命令从标准的输入中读取一行,并把输入方的每个字段的值指定给shell变量
#echo "OK! \n"
#echo -e "OK! \n" # -e 开启转义
#echo -e "ok! "
#echo "It is a test !!!" > myfile
#echo `date`
#read firststr secondstr
#echo "第一个参数:$firststr;第二个参数:$secondstr"
read -p "请输入一段文字:" -n 6 -s password
echo -e "\npassword is $password"
#-p 输入提示文字
#-n 输入字符长度限制(达到6位,自动结束)
# -t 输入限时
#-s 输入隐藏内容
__________printf__________
#!/bin/sh
#printf 也是一个shell输出命令命令模仿c程序库(library)里的printf()程序,移植性比echo好,语法:printf format-string [arguments...],参数一:格式控制的字符串,参数二:参数列表
#printf 'hello,shell\n'
#printf "%-10s %-8s %-4s\n" 姓名 性别 体重KG
#printf "%-10s %-8s %-4s\n" 郭靖 男 66.1234
#printf "%-10s %-8s %-4s\n" 杨过 男 48.6543
#printf "%-10s %-8s %-4s\n" 郭芙 女 47.9876
#%s %c %d %f 都是格式替代符
#%d Decimal 十进制整数 -- 对应位置参数必须是十进制整数,否则报错
#%s String 字符串 -- 对应位置参数必须是字符串或者字符型,否则报错!
#%c: Char 字符 -- 对应位置参数必须是字符串或者字符型,否则报错!
#%f: Float 浮点 -- 对应位置参数必须是数字型,否则报错
#printf "%d %s\n" 1 "abc"
#printf '%d %s\n' 1 "abc" #单引号与双引号的输出效果一致
#printf %s hello,world! #没有引号也可以输出
#printf %s hello world #只制定了一个参数,但多出的参数仍然会按照该格式输出,format-string被重用
# printf "%s\n" hello world
# printf "%s %s %s \n" a b c d e f g h i j
# printf '%s and %d \n' #如果没有arguments,那么%s用null代替,%d用0代替
# #转义序列:
# \a 警告字符
# \b 后退
# \c 抑制(不显示)输出结果中任何结尾的换行字符(只在%b格式指示符控制下的参数字符串中有效)
# \f 换页(formfeed)
# \n 换行
# \r 回车(Carriage return)
# \t 水平制表符
# \v 垂直制表符
# \\ 一个字面上的反斜杠字符
# \ddd 表示1到3位数八进制值的字符。仅在格式字符串中有效
# \0ddd 表示1到3位的八进制值字符
printf '%s and %d and %c and %4.4f \n ' '1+1=' 2 'True' 12323.1415
资源来自:http://www.runoob.com/
shell之echo and printf的更多相关文章
- [ SHELL编程 ] echo和printf使用实例
本文主要描述Linux系统中echo和printf命令的使用方法,包括命令参数的含义.使用技巧. 1.echo 了解一个命令我们首先要知道它能做什么,它有哪些参数,参数的含义,可以实现我们哪方面 ...
- shell 的echo和 printf
shell的echo指令是输出语句 就好比Python的print 在显示字符串的时候可以省略双引号 但是最好还是带上 echo ' Ti is a dashaobing' echo Ti is ...
- shell之echo与printf和颜色
在用户的bashrc中添加一行export来修改提示符.
- shell脚本--echo和printf打印输出
bash&shell系列文章:http://www.cnblogs.com/f-ck-need-u/p/7048359.html 注:本文关于引号等特殊符号的处理仅仅只是几个例子,想要彻底搞明 ...
- shell入门笔记2:字符串、数组、echo与printf
说明: 本文是关于http://c.biancheng.net/cpp/shell/的相关笔记 shell字符串 字符串可以用单引号,也可以用双引号,也可以不用引号. 1 #!/bin/bash 2 ...
- shell echo/read/printf/流程控制章节笔记
// echo read printf 流程控制 命令 1.read 命令从标准输入中读取一行,并把输入行的每个字段的值指定给 shell 变量 read hello 输入xxx echo $hell ...
- Shell 变量/echo命令
Shell 教程 Shell 是一个用C语言编写的程序,它是用户使用Linux的桥梁.Shell既是一种命令语言,又是一种程序设计语言. Shell 是指一种应用程序,这个应用程序提供了一个界面,用户 ...
- Shell(三):echo、printf、test命令
一.echo 1.显示普通字符串: echo "today is a wonderful day" 这里的双引号可以省略. 2.显示转义字符: echo "\" ...
- echo和printf打印输出
[root@node2 scprits]# echo Hello World! Hello World! [root@node2 scprits]# echo 'Hello World!' Hello ...
随机推荐
- DOM节点(二):操作节点
appendChild() 用于向childNodes列表的末尾添加一个节点. var returnedNode = someNode.appendChild(newNode); 如果传入的节点已经是 ...
- BZOJ 3233: [Ahoi2013]找硬币
BZOJ 3233: [Ahoi2013]找硬币 标签(空格分隔): OI-BZOJ OI-DP Time Limit: 10 Sec Memory Limit: 64 MB Description ...
- arXiv 上传文章过程
arXiv属于预印本服务的一种,是指科研工作者的研究成果还未在正式出版物上发表,而出于和同行交流目的自愿先在学术会议上或通过互联网发布的科研论文.科技报告等文章.与刊物发表的文章以及网页发布的文章 ...
- inline-block问题
1.两个相邻的inline-block元素,给inline-block元素设置max-width并且overflow:hidden;之后,相邻行内元素回向下偏移问题 给inline-block元素添加 ...
- Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting 'name pattern' at character position 36
例: <aop:config> <aop:pointcut expression="execution(* com.zsn.Service.Impl.*.*(..))&qu ...
- angularjs处理多个$http
本文引自:https://www.cnblogs.com/xiaojikuaipao/p/6017899.html 在实际业务中经常需要等待几个请求完成后再进行下一步操作.但angularjs中$ht ...
- linux防火墙的管理和策略控制
iptables 一:IPtables防火墙的简介 IPTABLES 是与最新的 3.5 版本 Linux 内核集成的 IP 信息包过滤系统.如果 Linux 系统连接到因特网或 LAN.服务器或连接 ...
- 【Python3】操作文件,目录和路径
1.遍历文件夹和文件 Python代码 import os import os.path rootdir = "d:/test" for parent,dirnames,fi ...
- 基于form表单submit提交不跳转
方法一:target <html> <body> <form action="" method="post" target=&qu ...
- NOIP PJ游记
Day -1 感觉自信满满,一等奖应该稳了,毕竟初一时我这么菜都拿了二等奖,然后就睡觉了... Day 1 在大巴上玩元气骑士可开心了,车上欢欢喜喜,到了考场,一眼看题,以为很简单. T1硬模拟... ...