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.

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 *
  • 1
    @Saith then you should accept the answer! – Putnik Jan 15 '18 at 20:53

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.