shell| When you enter an interaction, the input results are displayed on the same line as the prompt statement

Source: Internet
Author: User

Normal way:

#! /bin/bashecho "Please enter your name:" Read Nameecho "your name is $name." 123456

result:

[Email protected] ~]#./jiaohu.sh Please enter your name:yvesyour name is Yves. [[email protected] ~]# 12345

The following two ways to resolve user input values and prompts in the peer display:

    • echo mode

In the ordinary way add -n parameter can be either:

#! /bin/bashecho -n  "Please enter your name:"    #-n  Represents a non-newline read nameecho  "your name is  $name  ." 123456 

result:

[Email protected] ~]#./jiaohu.sh Please enter your Name:yvesyour name is Yves. [[email protected] ~]# 1234
    • Read mode

Download the prompt statement to read and add the parameter -p

#! /bin/bashread -p  "Please enter your name:"   name       #将用户输入的值保存到变量name中echo   "your name is  $name  ." 1234 

result:

[Email protected] ~]#./jiaohu.sh Please enter your Name:yvesyour name is Yves. [Email protected] ~]#


shell| When you enter an interaction, the input results are displayed on the same line as the prompt statement

Related Article

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.