After doing "cd [some directory]", you can do "cd -" to return to the previous directory. Consider when NAME1 is something like "directory/subdirectory" - the "cd .." will not return to the original directory, but "cd -" will.
In fact, you don't really need to change directory at all... you can do:
ls will output the contents of "dirname" if it is a directory, so you can assign your variables simply like this:
Code:
x=$(ls "$NAME1" |wc -l)
y=$(ls "$NAME2" |wc -l)
The greater than operator is -gt (-lt is less than, -ge is greater than or equal to, and so you can probably guess what -le is). In shellscript the ">" character re-directs the output of the statement to the left of the character into the file to the right of it. You will probably have some files whose names are numbers after running your script
Use "elif" not, "else if". Why every language on the planet has to invent a new way to say "else if" I do not know, but heh.
Use [code] tags, not [quote] tags when posting code. It looks much better (fixed width font, preserved whitespace).