I'm writing a shell script that is supposed to take in one parameter (a directory name) and display how many files, directories, readable files, writable files and executable files are in that directory. If a parameter isn't given when you run it, its supposed to display an error message and abort. If the given parameter doesn't exist it should also display an error message and abort. Otherwise it should display the above info. I cannot for the life of me get it to run. Here is what I have, please help!:
#!/bin/csh
$1
set file=$1
if ($file==0)then
echo "usage: assignment6.sh <directory_name>"
exit0
else
if (-e $file && -r $file) then
echo "Number of Directories: `ls | wc -w`"
echo "Number of Files: `ls -d */ | wc -w`"
echo "Number of Readable files: `find * -type f -or -type d -maxdepth 0 -perm +u=r | wc -w`"
echo "Number of Writable files: `find * -type f -or -type d -maxdepth 0 -perm +u=w | wc -w`"
echo "Number of Executable files: `find * -type f -or -type d -maxdepth 0 -perm +u=x | wc -w`"
else
if (! -e $file) echo "No such directory."
exit 0
endif
endif
exit 0
csh
. In my defense I was never a fan ofcsh
and I haven't used it in the last 20 years...bash
, it'scsh
. Inbash
theif
construct isif
condition; then
then-partelse
else-partfi
. Incsh
it is like you wrote,if (
condition) then
then-partelse
else-partendif
. Inbash
assignment is plain variable=
value --set
is fromcsh
.csh
you should add the proper shebang to the top of your script#!/bin/csh