basename problem

Hi guys if i do

a=`basename -e -s /home/j/john/*`

du -k -h $a | sort -nr | head -10

why when i run the script does it work but also say usage basename string [suffix]

any ideas thanks

Hi,
What did You expect for output? I don't think basename has the options -e and -s, are You perhaps thinking of some other command?

/L

Well i took the -s sand -e and i get the same

i just want to cut the /home/j/john and print the directory names in that path

so rather then

/home/j/john/directory/
/home/j/john/directory2/pictures

it should list it

.directory
.pictures

im trying to list the 10 largest files in the users home directory but i dont want to display the whole path just the last folder

Hi again,
yes because even if You remove the -s and -e it may still be syntactically wrong, probably because the wild card * expands to more arguments than base name expects.

A few ways to get the dir names from a directory could be

ls -d /home/lakris/*/
find /home/lakris  -maxdepth 1 -type d

or even

tree -d -L 1 /home/lakris

if You have it. But perhaps not so good for scripting!
After You've got the names, You can treat hem with basename to get the basic file (dir) name You want.

An example:

ls -1 -d /home/lakris/*/|while read line; do basename $line;done

i do this and i get the expected correct result but i still get an error saying no such file or directory found

a=`ls -1 -d /home/j/jdongs/*/|while read line; do basename $line;done`

not sure why

Hi, I am not sure what that could be, can You post some output? Maybe there are dirnames with space in them? To handle that, use quotes around the variable, do basename "$line".
And will You do any operations based on the variable "a" or on the read input in the while loop? I would recommend the latter. The var "a" will contain a row of words and if a directory contains of several words You won't be able to discriminate between the words/directory names in "a". Otherwise You may have to use an array.

/Lakris

/home/j/jdongs/*/: No such file or directory

The 10 biggest directories are:
size Directory
960 k ./dir1
928 k ./.tin
808 k ./files

it just prints 10 of the biggest directories but for some reason does it correcty but comes up wth No such file or directory

 #!/bin/sh


    fnGetUserQuota ()
    {
        #Below is a variable declaring the threshold limit for the quota

        limit=24

        #prints quota's on all file systems then greps the line with /home
        # The $2 is the usage and %3 is the quota. The calculation results in
        # the amount of quota being used. This is all stored in the variable 'q'

        QuotaResult=`quota -v | grep '^/home' | awk '{print int($2/$3*100)}'`
   }
   
   fnTestQuota ()
   {
        #The if statement tests if QuotaResult is more then the threshold limit
        #If its greater consider reducing your usage otherwise just prints current
        # usage

        #start of test statement

        if  [  $QuotaResult  -gt  $limit  ] 
        then
            echo "you are currently using  $QuotaResult %  of your quota "
            echo "consider reducing your usage"
            return 0        
        else
            echo "you are currently using $QuotaResult of your quota"
            exit 0

        fi
    
        #end of test statement
    }

    fnListDirectories ()
    {
        count_num=10
        blank_white=echo""
a=`ls -1 -d /home/j/jdongs/*/|while read line; do basename "$line";done`
        $blank_white
        echo "The 10 biggest directories in your home directory are:"
        

        echo "Size    Directory"
        echo "----    ---------"

        #The following prints the largest to smallest directories sorts them
        # numerically in reverse but only lists the first 10 in kilobytes
        # in a human readable format
        
        $blank_white
      
        du -k -h $a | sort -nr | head -$count_num
    }

    fnGetUserQuota
    fnTestQuota
    fnListDirectories

    exit 0



Ok, maybe You have directories with names including spaces?
Try to include this for debugging before the du command:

echo This is a:
for x in $a;do echo $x;done
echo This is ls output:
ls -1 -d /home/j/jdongs/*/|while read line; do basename "$line";done

To see if they give similar output.
/L

PS Btw, have You tried using just

du -k $dirname |sort -nr

etc...
It will list the directories for You?

/L

ok ill try it now and ill let you know what i get thanks for assisting