It is my understanding that when writing a Unix shell program you can iterate through a string like a list with a for loop. Does this mean you can access elements of the string by their index as well?
For example:
foo="fruit vegetable bread"
How could I access the first word of this sentence? I’ve tried using brackets like the C-based languages to no avail, and solutions I’ve read online require regular expressions, which I would like to avoid for now.
Pass
$fooas argument to a function. Than you can use$1,$2and so on to access the corresponding word in the function.EDIT: another better version is:
EDIT(2): have a look at this thread.