Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"for i" without "in [sequence]" ending while using getopt

Tags:

bash

shell

getopt

I've found this example script for using getopt command in shell.

#!/bin/bash
args=$(getopt ab $*)
set -- $args
for i;
do
  case "$i" in
    -a)shift; echo "it was a";;
    -b)shift; echo "it was b";;
  esac;
done

It works well, but I don't understand where is variable $i assigned. How it knows that it must iterate through $arg. Can you explain this?

like image 505
sev3ryn Avatar asked Apr 19 '13 10:04

sev3ryn


1 Answers

As shown here, for defaults to $@ if no in seq is given. The for i assigns your $i variable.

like image 97
d33tah Avatar answered Nov 14 '22 11:11

d33tah