Shell Summary: Select expressions and for Loops

Source: Internet
Author: User

The Select expression is a bash extension application, especially for interactive use. You can select from a group of different values.
Select VaR in...; do
Break
Done
... Now $ VaR can be used ....
The following is an example:
#! /Bin/sh
Echo "What is your favorite OS? "
Select VaR in "Linux" "GNU Hurd" "Free BSD" "other"; do
Break
Done
Echo "you have selected $ Var"
The following is the result of running the script:
What is your favorite OS?
1) Linux
2) GNU Hurd
3) Free BSD
4) Other
#? 1
You have selected Linux

 

The for-loop expression is used to view a string list (strings are separated by spaces) and then assigned to a variable:
For VaR in...; do
....
Done

In the following example, ABC is printed to the screen:
#! /Bin/sh
For var in a B C; do
Echo "Var is $ Var"
Done

Output all files starting with test on the screen:

For VaR in $ (LS test *); do
Echo $ VaR
Done

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.