免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1011 | 回复: 0
打印 上一主题 下一主题

linux下的printf and echo commands [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-08-19 14:55 |只看该作者 |倒序浏览

               
               
                echo
echo - display a line of text
SYNOPSIS
echo [OPTION]... [STRING]...
DESCRIPTION
NOTE: your shell may have its own version of echo which will supercede
the version described here. Please refer to your shell's documentation
for details about the options it supports
Echo the STRING(s) to standard output.
-n do not output the trailing newline
禁用自动换行
-e enable interpretation of the backslash-escaped characters listed below
启用转义字符的解释
-E disable interpretation of those sequences in STRINGs
将字符串当作一个整体
--help display this help and exit
显示帮助信息
Without -E, the following sequences are recognized and interpolated:
\\ backslash
\a alert (BEL)
\b backspace(退格)
\c suppress trailing newline(禁止自动换行)
\f form feed(原始格式)
\n new line(换行)
\r carriage return(将\r后面的内容输出,并覆盖\r前面的内容)
\t horizontal tab(水平tab)
\v vertical tab
printf
 syntrax
printf( format, value, value ...)
This syntax is like that of the printf command in the C language,
and the specifications for the format are the same. You define the
format by inserting a specification that defines how the value is to be
printed. The format specification consists of a % followed by a letter.
Like the print command, printf does not have to be enclosed in
parentheses, but using them is considered good practice.
The following table lists the various specifications available for the printf command.
Specification Description
%c     Prints a single ASCII character
%d    Prints a decimal number
%e       Prints a scientific notation representation of numbers
%f     Prints a floating-point representation
%g     Prints %e or %f; whichever is shorter
%o     Prints an unsigned(无符号) octal(八进制) number
%s     Prints an ASCII string
%x     Prints an unsigned hexadecimal(十六进制) number
%%     Prints a percent sign; no conversion(转换) is performed
You can supply some additional formatting parameters between the %
and the character. These parameters further refine(精练,简洁) how the value
is printed:
Parameter Description
-         Left justifies(对齐) the expression in the field
width     Pads(填充) the field to the specified width as needed (a leading zero pads the field with zeros)
.prec     Maximum string width or the maximum number of digits to the right of the decimal point
example:
printf "%-16s%-16s\n" "1namedds" "hegffg";
printf "%-16s%-16s\n" "2name" "he";
printf "%-16s%-16s\n" "3namesdsdds" "hegfgf"
printf "%16s%16s\n" "4namesdsdd" "hegg"
printf "%16s%16s\n" "5namef" "hegfgfgfgfgg"
printf "%16s%16s\n" "6namef" "hegffgfgfggfg"
if  test -n "$NAME" ;then #if variable no the double quote,the else do not execute.
  echo $NAME      #(如果没有双引号,else语句不会执行)so, the double quote is needed.
  else
  echo "no name exist"
fi
echo -e "the variable equal to -n\c"
echo -e "hello,\n how are you"
echo -e "hello\t how are you"
assume the file 2.txt content follow:
#!/bin/bash
hammers 5       7.99
drills  2      29.99
punches 7       3.59
drifts  2       4.09
bits   55       1.19
saws  123      14.99
nails 800        0.19
screws 80        0.29
brads 100        0.24
$awk '{printf "%s  %s\n",$1,$2}


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/45689/showart_363352.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP