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}
|
阅读(569) | 评论(0) | 转发(0) |