Analysis of the colon ":" command

Source: Internet
Author: User

The colon ":" command is a control command. it is occasionally used to simplify logical conditions, which is equivalent to a false alias. because it is built-in, it runs faster than true, but its readability is much worse. the reader may see it in a condition of the while loop. "while:" indicates that this is an infinite loop, which is equivalent to the more common "while true ". ":" It is also used for conditional setting of variables, for example, 1: $ {var: = value}. If no ":", shell will try to interpret $ var as a command. in some old shell script programs, you will publish a colon that is used at the beginning of a line to cause a comment, but modern script programs always start a comment line, this is because the execution efficiency is higher. 01 #! /Bin/sh02 03rm-f fred04 05if [-f fred]; then 06: 07 else 08 echo file fred did not exist09fi10 11 exit 0

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.