Navigation X
ALERT
Click here to register with a few steps and explore all our cool stuff we have to offer!



 3947

Bash Scripting Count only files we own

by Black_Kais3r - 11 April, 2019 - 11:47 PM
This post is by a banned member (Black_Kais3r) - Unhide
68
Posts
38
Threads
6 Years of service
#1
Code:
#!/bin/bash
# Counting the number of lines in a list of files
# for loop over arguments
# count only those files I am owner of

if [ $# -lt 1 ]
then
 echo "Usage: $0 file ..."
 exit 1
fi

echo "$0 counts the lines of code"
l=0
n=0
s=0
for f in $*
do
 if [ -O $f ] # checks whether file owner is running the script
 then
     l=`wc -l $f | sed 's/^\([0-9]*\).*$/\1/'`
     echo "$f: $l"
     n=$[ $n + 1 ]
     s=$[ $s + $l ]
 else
     continue
 fi
done

echo "$n files in total, with $s lines in total"
This post is by a banned member (hasi912) - Unhide

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
or
Sign in
Already have an account? Sign in here.


Forum Jump:


Users browsing this thread: 1 Guest(s)