Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2011
    Posts
    3

    Unanswered: Shell Program error output help

    I am writing a program to get the amount of blocks a file/directory occupy calling it blc
    so if you type:
    blc a b c d
    it would output the number of blocks occupied by normal files in those directories (added together)
    output would be:
    WARNING: c could not be accesses
    WARNING: d is not a directory
    608
    i'm going to add my other program to it using
    (( numblocks=$(getblocks file1) ))
    my other program getblocks:
    if test -e "${1}"
    then
    ls -sd ${1}|sed 's/^ *//'|cut -d' ' -f1
    else
    echo 0
    fi

  2. #2
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Seems to me it would be much simpler to use 'du'

    Code:
    du -s a b c d
    Then add the 4 lines of output to get the grand total.

  3. #3
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    Also what is the difference between your two warnings:
    • c could not be accesses
    • d is not a directory
    when would you show one and not the other?

  4. #4
    Join Date
    Apr 2011
    Posts
    3
    Quote Originally Posted by mike_bike_kite View Post
    Also what is the difference between your two warnings:
    • c could not be accesses
    • d is not a directory
    when would you show one and not the other?
    Such as if a directory wasn't accessible due to permissions. And the other is if one or more of the files specified wasn't a directory

  5. #5
    Join Date
    Apr 2011
    Posts
    3
    Quote Originally Posted by kitaman View Post
    Seems to me it would be much simpler to use 'du'

    Code:
    du -s a b c d
    Then add the 4 lines of output to get the grand total.
    Thanks that probably would of been easier but
    sorta new to the programming in unix so at least i got a chance to work it out. plus it's already written through sed to just give just the block outputs.

  6. #6
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Instead of using test -e, use test -d to see if the input is the name of a directory rather than a file

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •