Skip to main content
Tweeted twitter.com/StackUnix/status/953074012963459077
edited tags
Link
Gilles 'SO- stop being evil'
  • 865.4k
  • 205
  • 1.8k
  • 2.3k
edited title
Link
Stéphane Chazelas
  • 584.9k
  • 96
  • 1.1k
  • 1.7k

Bash code confusion"for" loop without a "in foo bar..." part

Source Link
user270650
  • 361
  • 3
  • 3

Bash code confusion

I was recently looking at some code that confused me because it works and I didn't expect it to. The code reduces to this example

#!/bin/bash
for var;
do
  echo "$var"
done

When run with command line arguments is prints them

$ ./test a b c
a
b
c

It is this, that is (to me) unexpected. Why does this not result in an error because var is undefined ? Is using this considered 'good practice' ?