Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
The problem statement, all variables and given/known data:
A script that takes any number of directories as command line arguments and then lists the contents of each of these directories. The script should output each directory name prior to listing the files within that directory
Relevant commands, code, scripts, algorithms:
No of dir = $#
count=1
If [ count -le $# ] then;
echo ${$count}
ls �ltr ${$count}/
count = `expr count + 1`
fi
The attempts at a solution (include all code and scripts):
No of dir = $#
count=1
If [ count -le $# ] then;
echo ${$count}
ls �ltr ${$count}/
count = `expr count + 1`
fi
Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
BITS pilani, Hyderabad, India, B.V. Prasad Babu, System Programming
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
1) Variables can't have spaces in their names. No of dir = $# is wrong.
2) You shouldn't put spaces on either side of the equal sign. something = asdf is wrong. Do something=asdf
3) You got your if-statement nearly right, but not quite. Don't capitalize anything. Your ; is also in the wrong place.
If it helps, imagine it like this:
if [ something ]
then
...
fi
To combine any of that onto one line, you'd put ; where there's newlines, so you'd get if [ something ] ; then
4) You can't put a variable in a variable like this: ${$count} it just doesn't expand there. There's a better way, anyway.
The shift command will get rid of the first parameter. If your parameters were a b c d before, after you run shift they will be b c d . So you can loop until $# is zero, running shift at the bottom of your loop, using $1 every time instead of using $1, $2, $3...