I was reading a book on shell scripting and found this example:
This little script works as expected and accepts multiple arguments, but how does it substitute the values of the "STRING" variable when "shift" is not inside the loop?Code:#!/bin/sh pattern="$1" shift echo "Matching against '$pattern':" for string do case $string in $pattern) echo "$string: Match." ;; *) echo "$string: No match." ;; esac done
I am new to shell scripting but I just hate it when I find something that works and I don't know why it works. No troubleshooting can give me an answer to this one so I thought I try the forums. Also, using "for" without some kind of a list/array is poorly documented on the internet.
Bookmarks