Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the until command of Shell

Shulou Source: shulou.com Published: 2022-06-01 15:52:01 10月03日 Update

This article mainly introduces the Shell until command how to use the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that we read this Shell until command how to use the article will have a harvest, let's take a look.

The until command works the exact opposite of the while command. The until command specifies a test command that usually returns a non-zero exit status code. When the exit status code of the test command is not 0, Bash Shell executes the command in the loop; when the exit status code of the test command is 0, the loop ends.

Until syntax format: until conditiondo commanddone

Condition is generally a conditional expression, and if the return value is false, the statement inside the loop continues to be executed, otherwise it jumps out of the loop.

For the following example, we use the until command to output numbers from 0 to 9:

#! / bin/basha=0until [! $a-lt 10] do echo $a = `expr $a + 1`done run result:

The output is as follows:

0123456789 this is the end of the article on "how to use the until command of Shell". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to use the until command of Shell". If you want to learn more, you are welcome to follow the industry information channel.

Tags: Command loop state knowledge test content article result output value instance loop body simple operation number article way easy to understand more condition format Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Apple Redmi OPPO Reno vpn