In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Shell printf command
The echo command is mainly used for string output. It can be used without quotation marks but does not support escape. Double quotation marks can be used to escape characters.
The printf command is also an output command, but it is more portable than echo. You can define the width of the string and adjust it left and right; you can format control characters, specify parameter lists, distinguish parameter spaces, and syntax structure:
Printf format-string [arguments...]
#! / bin/bash#author:zrc# automatic line wrapping comparison echo-e "OK!\ n" #-e enable escape\ nenable line wrapping echo "is an echo" echo "-" printf "good, shell,\ npython" # output: OK! Is an echo--good, shell,python
Printf formatting
#! / bin/bash#author:zrcprintf "%-10s%-8s%-4s\ n" id name ageprintf "%-10s%-8s%-4s\ n" 1 jeey 18printf "%-10s%-8s%-4.2f\ n" 2 tom 19printf "%-10s%-8s%-4.2f\ n" 3 king 20printf "%-10s%-8s%-4.2f\ n" 4 quren 33.33mm output id name age 1 jeey 18 2 Tom 19.003 king 20.004 quren 33.33% quren 10s%-8s%-4s\ n are formatted for parameter categories%-10s-the first parameter must be a string string (- 10 indicates a width of 10 characters and left alignment) No-indicates right alignment If it is not a character or string, the error must be%-8s-- the second bit parameter must be a string string (- 8 indicates a width of 8 characters and is left-aligned, no-indicates right alignment; if it is not a character and string, an error is reported)%-4s-- the third bit parameter must be a string string (- 4 indicates a width of 4 characters and left-aligned, no-indicates right alignment) Error if it is not a character or string)%-4.2f-- the third bit parameter must be float floating point (- 4.2 means the width is 4 formatted decimals, keep the last two digits, no-indicates right alignment; error if it is not an integer)
Printf case
More cases:
#! / bin/bash#author:zrc# has no quotation marks printf% s\ n 'aaaaa # single quotation marks printf'% d% s\ n '123456' aaaaa'# double quotes printf "% s\ n"' 123456' bbbbb'# exceeds the specified number of parameter format-string and will be reused by printf "% d% s\ n" '123456' aaaaa'' 456789' ccccc'# if there is no parameter, then% s will be replaced by NULL % d uses 0 instead of printf "% s -% d"'\ nstring% c automatically intercepts the first character of the string as the result output printf "% d% c\ n" '123456' bbbbb'%d% s% c% f are formatted% d-decimal integers for parameter categories (the corresponding parameter bits must be integers If not, report an error)% c-Char character (the corresponding parameter bit must be a string or character type, if not, an error is reported)
Prinf escape character sequence description\ a warning character, usually ASCII's BEL character\ b back\ c suppresses (does not display) any newline characters at the end of the output (valid only in parameter strings controlled by the% b format indicator), and any characters left in the parameters, any subsequent parameters, and any characters left in the format string All are ignored\ f page feed (formfeed)\ nline feed\ r enter (Carriage return)\ t horizontal tab\ v vertical tab\\ a literal backslash character
The Shell echo command #! / bin/bash#author:zrc# displays the string echo "this is string" # shows the escape character echo "\" this is string\ "# shows the result directed to the file Symbol > > append to file echo "this is string" > file# shows the input variable read name echo-e "this is ${name}\ n" #-e enables escape-n wrapping echo-e "this is ${name}\ c" #-e turns on escape-c does not break read password-p "Please enter a paragraph:"-n 6-t 5-secho-e "\ n password is $password" parameter description :-p input prompt text-n input character length limit (up to 6 digits Auto end)-t input time limit-s hide input
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.