Avoid undesired echo methods

Source: Internet
Author: User
Avoid undesired echo methods. most popular Unix and Linux versions have an echo command. It contains the-n option to disable line breaks, but not all versions are the same. Some versions of echo commands use \ c as a special embedded character to prohibit line breaks, and some must be replaced... avoid undesired echo methods. most popular Unix and Linux versions have an echo command. It contains the-n option to disable line breaks, but not all versions are the same. In some versions, echo commands use \ c as a special embedded character to disable line breaks. in other versions, line breaks are required before output. To understand what your echo version is like, you can simply enter The following statement on The command line: echo-n "The rain in Spain "; echo "falls mainly on the Plain" if your echo has The-n option, there will be: the rain in Spain falls mainly on the Plain if not, it is another scene: -n The rain in Spain falls mainly on the Plain ensures that The script output is presented to the user as required. this becomes increasingly important as The script interaction increases. Code: 01 #! /Bin/sh02 03 # There are many methods in this book to solve this echo problem. Among them, my favorite method is very simple: 04 function echon05 {06 echo "$ *" | awk '{printf ("% s", $0)}' # note, in the original text, there are no parentheses. after testing, the awk version I used is not supported, and all the brackets are added, like C07} 08 09 10 # you may want to avoid calling the awk command internally. However, if you have a user-level printf command, you can use it instead of 11 #: 12 echon () 13 {14 printf "% s" "$ *" 15} 16 17 # If you do not have the printf command and do not want to call awk, use the tr command: 18 echon () 19 {20 echo "$ *" | tr-d "\ n" # for parameters, refer to page 21} 22 on the manual page. # The version of this tr command is a very effective and simple script for running: when using this script, you only need to use the simple replacement of echon when calling the echo command, so that the line breaks will not automatically. 01 #! /Bin/sh02 03 function echon04 {05 echo "$ *" | awk '{printf ("% s", $0 )} '06} 07 08 echon "Enter coordinates for satellite acquisition:" 09 echo "HH" 10 exit 0 output :. /poorEcho. sh Enter coordinates for satellite acquisition: HH

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.