How to write for-loop in ESXi shell
search cancel

How to write for-loop in ESXi shell

book

Article ID: 410926

calendar_today

Updated On:

Products

VMware vSphere ESXi

Issue/Introduction

A typical for-loop does not work in the ESXi shell.

[root@localhost:~] for i in {1..5}; do echo $i; done
{1..5}
[root@localhost:~] for ((i=1; i<=5; i++)) ; do echo $i; done
-sh: syntax error: bad for loop variable

Environment

VMware ESXi
VMware ESX

Cause

ESXi uses a BusyBox-based lightweight shell (ash), and its functionality is limited.

Resolution

Use the seq command instead of shell expansion.

[root@localhost:~] for i in $(seq 1 5); do echo $i; done
1
2
3
4
5