shell脚本文件中for循环的两种写法

点击个人博客,查看更多文章https://elonjelinek.github.io/

#!/bin/bash

for (( i = 0; i <= 10; i++ )) ;
do
    echo "The value is: $i"
done

echo -e "\nJourneys end in lovers' meeting."
echo -e "A friend in need is a friend indeed.\n"

for num 1 2 3 4 5 ;
do
   echo "The number is: $num"
done

运行结果:

ElonJelinek:Desktop ElonJelinek$ ./test.sh 
The value is: 0
The value is: 1
The value is: 2
The value is: 3
The value is: 4
The value is: 5
The value is: 6
The value is: 7
The value is: 8
The value is: 9
The value is: 10

Journeys end in lovers' meeting.
A friend in need is a friend indeed.

The number is: 1
The number is: 2
The number is: 3
The number is: 4
The number is: 5
ElonJelinek:Desktop ElonJelinek$ 

点击个人博客,查看更多文章https://elonjelinek.github.io/

你可能感兴趣的:(Linux)