Script Question

I have a script that will calculate some information about the current directory that I run the script in. How can I have it where it gets an argument from the user(such as a directory) and the script calculate the information for the given directory? Any help is greatly appreciated.

can you post your script??

I still have alot of work to do I know but I'm knew at this.

#!/bin/sh

echo "Total number of directories:"
ls -l | grep -c "^d"
echo "Total number of files:"
ls -l | grep -c "^-"
echo "Total number of readable files:"
ls -l | grep -c "^.r"
echo "Total number of writable files:"
ls -l | grep -c "^..w"
echo "Total number of executable files:"
ls -l | grep -c "^...x"

so you want to give a directory path as an argument to your script??
if so

scriptname PATH

inside script

cd $1
.
.
.
your script

Consider your script name is "testing.sh".

Inside the Script you are calculating some information about the current directory..

$ ls -lrt /home
$ # do some operation with the directory

You can pass an argument from the user by

1) consider the user is having permission to trigger the script, use

$ testing.sh "/home"

the user can give like this also

$ testing.sh /home

Insdie the script you can have retrieve the argument by

$ ls -lrt $1
$ # do some operation with the directory

2) Suppose user is not triggering the script. you have to get the input by

$ testing.sh

Inside the script..

$ #!/bin/sh
$ echo -n 'what is the value? '
$ read VALUE
$ ls -lrt $VALUE
$ # do some operation with the directory

one more thing you want to count the dir and files or want to display it??
if you want to count you can use the following one liner

cd $1
ls -l $1|awk '/^d/{dir+=1}/^-/{file+=1}/^.r/{read+=1}/^..w/{write+=1}/^...x/{exe+=1}END{print "Total number of directories : "dir"\nTotal number of files : "file"\nTotal number of readable files : "read"\nTotal number of writable files : "write"\nTotal number of executable files : "exe}'

Ok I understand the cd $1 concept on getting the directory from the user but I thought there was a way to make the script not even execute unless the user typed in an argument or parameter right after typing the scriptname. So if the user just runs the scipt without giving a directory I dont want it to run. Make sense? Sorry again I'm new at this. Thank you for your time though.

User can trigger this sample.sh ( consider the user is going to use this script).

When user trigger this script they will be asked to enter the directory name after that only operation will take place.. Try this

$ #!/bin/sh
$ echo -n 'what is the directory name? '
$ read VALUE
$ ls -lrt $VALUE
$ # do some operation with the directory

Check this one..

check if the total number of parameters passed is 1

if [ $# -gt 1 ]
then
<your regular processing here>
else
echo "This needs atleast one parameter"
fi