2 ms·
Here is the part of the test.c source from V7 Unix: main(argc, argv) char *argv[]; { ac = argc; av = argv; ap = 1; if(EQ(argv[0],"[")) {
by projektfu 9mo ago
Here is the part of the test.c source from V7 Unix:
main(argc, argv)
char *argv[];
{
ac = argc; av = argv; ap = 1;
if(EQ(argv[0],"[")) {
if(!EQ(argv[--ac],"]"))
synbad("] missing","");
}
argv[ac] = 0;
if (ac<=1) exit(1);
exit(exp()?0:1);
}
So, if the professor was missing the "[" command, they were missing a link. More likely, they had a weird orthodoxy about using "test" instead of "[" because reasons. One good reason to use "test" instead of "[" in a Bourne shell control statement is if you are running a list of commands between "if" and "then", and the test is the last part of the list.
Another good place to use "test" is if you are not in a control statement and you are just setting $?.
Edit: EQ() is defined as:
#define EQ(a,b) ((tmp=a)==0?0:(strcmp(tmp,b)==0))
char *tmp;