TIP: Click on subject to list as thread! ANSI
echo: muffin
to: Roy J. Tellason
from: Wes Garland
date: 2003-06-15 11:08:52
subject: Maximus at UNIX

preface: sorry for the crappy format, I lost my connection to juge.com
halfway through writing this (damn internet!)
 
 RJT> I have not done near enough with bash to know what the heck I'm 
 RJT> doing,  but thought that perhaps passing it a 
 RJT> parameter would work by changing that one line to

 RJT> for file in $1

 RJT> Does that look like it'd work?
 4: "$1" is a parameter which identifies the first argument in the current
 5: argument vector (let's call it argv). argv is passed from the calling
 6: program (usually a shell) to the shell script upon initialization.
 7: Remember, as well, that wildcards are expanded by the shell *before* argv
 8: is populated.
 9:
10: So, if you call a script like this:
11:
12: myscript.sh *
13:
14: argv will contain $1=fileone, $2=filetwo, $3=filethree -- assuming the
15: only files in your directory were fileone, filetwo, and filethree.
16:
17: You can also repopulate argv with the set command. "set one two three"
18: sets $1=one, $2=two, $3=three. If your set command contained wildcards,
19: they will be expanded by the shell before the set command is interpreted
20: (so set doesn't get wildcards, it gets its own argv as the expanded list
21: of files)
22:
23: [ offside -- a wildcard which matches nothing is not expand, but rather
24: passed as literal string ]
25:
26: so, the two following scripts are exactly equivalent:
27:
28: #! /bin/sh
29: for file in a b c
30: do
31:   echo $file
32: done
33:
34: and
35:
36: #! /bin/sh
37: set a b c
38: while [ "$1" ]
39: do
40:   echo $file
41:   shift
42: done
43:
44: Oh -- the shift command shifts all the arguments left one position, and
45: erases $1.
46:
47: If you're using the set command with wildcards or user input, may I
48: suggest the following syntax:
49:
50: set -- $list_of_elements ""
51:
52: This will prevent the first element in your list from being parsed as an
53: option if it happens to contain a dash (that's what the -- does), and the
54: "" will insure that set always receives at least one
argument; otherwise,
55: if no arguments are passed (e.g. $list_of_elements is empty), it will
56: display the current environment on stdout.
 
q
 RJT> And somehow I ended up with a file named a.out?  I 
 RJT> didn't think that was even still being used!  Oh 
 RJT> well...
 
Remember, backwards compatibility has always been very important in the
UNIX world. :)
 
TO specify the name of your output file, use '-o filename'.
 
Wes

--- Maximus/2 3.01
* Origin: COMM Port OS/2 juge.com 204.89.247.1 (281) 980-9671 (1:106/2000)
SEEN-BY: 633/267 270
@PATH: 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.