0

I'm working on a little script and I found another solution like the one I came up with use this line here:

for i in *; do

What exactly does the *; do/mean here? I'm used to seeing $ variables.

2 Answers 2

4
for i in *; do

The * here is the filename globbing character that matches all (non-hidden) names in the current directory.

In each iteration of the loop, the variable i will take the value of each of the names matching * in turn.

The ; after the * (as in most other places) may be replaced by a newline:

for i in *
do
1
  • 1
    @Saith then you should accept the answer!
    – Putnik
    Commented Jan 15, 2018 at 20:53
1

Per Confused about the behavior of asterisk in ls command

Asterisk expands before it gets to the [...your...] command

So you are passing all the files matching your pattern * to for

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .