Re: possible shell script solution

From: Christo (chris_at_juststuffd.co.uk)
Date: 12/03/04


Date: Fri, 3 Dec 2004 01:52:44 -0000


"Christo" <chris@juststuffd.co.uk> wrote in message
news:315s7mF37shksU1@individual.net...
> ok i posted earlier and thank you for all your replies, i have looked at
> your methods and tried to digest them and even tested a few, but none
> worked to my advantage unfortunately.
>
> i have posted a new thread because the other one was massive and strayed
> OT so here we go....
>
> I am a total novice and have no prior experience to shell scripting so
> please bare with me
>
> I have come up with this however there are several parts of it which i am
> not too sure about and wanted to check with you people here
>
> the purpose of the script (for people not familiar with the previous pst)
> is to list directories and files by simply listing their name, but only to
> list directories and files that are writeable by group and other it doesnt
> matter if they are writeable by owner or are readable etc as long they
> have a w in c6 and c9 so i have came up with this, it also must count the
> files and display the figures at the bottom of the script.
>
>
> #!/bin/sh
>
> dcount=0
> fcount=0
>
> for fn in *
> do
>
> dir=`ls -ld $fn | cut -c1`
> name=`ls -ld $fn | cut -c55-75`
> gwrite=`ls -ld $fn | cut -c6`
> owrite=`ls-ld $fn | cut -c9`
>
> if [ $gwrite = 'w' -a $owrite = 'w' ]
> then
>
> #havent been taught boolean in shell scripting at uni yet
> #but do i set the value with `` quotes or with '' quotes?
> #i simply want the write variable to hold the value w
> write=`w`
>
> if [ $dir = 'd' -a $write = 'w']
> then
>
> #below i am not sure if this will work? adding to the
> #dcount and adding to the fcount like this and also
> #outputting the names, seen as how both file names and
> #directory names share the same variable?
> #can anyone post a solution to this?
>
> dcount=`expr $dcount + 1
> echo "$name (DIR)"
> fcount=`expr $fcount +1
> echo "$name"
> else
> echo "0 files/dirs writeable by group and other"
> fi
> fi
> done
>
> echo "\n"
> echo "Counted $fcount Files"
> echo "Counted $dcount directories"
>
> any help here would be much appreciated, I am getting there eventually on
> my limited knowledge, i havent been taught any shell scripting this
> assignment is entirely based on me researching from the start, we have of
> course been told very basic stuff like the structure of the language and
> numerous commands and stuff, but nothing solid that can be put to good
> practice in creating a script such as this.
>
> thanks for your time
>
> Chris
>

this is proving quite difficult for me i have tried peoples suggested
scripts and they are failing for reasons i dont know.

i have managed to be able to get a list from one of the following methods

ls -l | cut -c55-75

this will list everything including directories

i have also managed

if [ -f $fname ]
then
    echo "$fname (File)"
else
    echo "$fname (DIR)"
fi

i am not sure how ths works, what exactly does -f do? and will -d do the
same except replace where the file is echoed the directory will be echoed?

i have tried this which is totally off

dir=`ls -ld $fn | cut -c1`

 if [ $dir = 'd' ]
 then
  echo "Writeable directories"
  ls -l | cut -c55-75
 else
  echo "no writeable directories"
 fi

the test will figure if the file is a sirectory, but the command ls -l |
cut -c55-75 will display all available contents of directory

can anyone tell me how to change the command

ls -l | cut -c55-75

so it will list only directories and not files too

if i can get that sorted i will b somewhat where i want to be,

able to list directories only

i could then try

owrite=`ls-ld $fn | cut -c9`
gwrite=`ls -ld $fn | cut -c6`

if [ owrite = 'w' && gwrite = 'w']
then
write="w"
           if [ $dir = 'd' && $write = 'w']
            then
            ls -l | cut -c55-75
#the above ls command doesnt work the way i want
#but a command that will list only directories?

is this right?

or is it -a for and and -o for OR?

i have been getting errors in my scripts with missing [] characters?

i am a total novice, this is a hard script for me to write, however what i
have learnt is that people who work in unix daily... are really cool people,
it must take so much time to get scripts and commands and stuff setup and
personalized.

anyhow any help would be much appreciated

can anyone point me to a good online tutorial on shell scripting?

the stuff we have from lectures is pretty crappy only scratches the
surface.... any reference material other than the long and horribley
designed man pages would be great

i have tried man test and i think i found test operators are -a and -o for
and and or?

i have been using || and &&

and is it

if [bah] && [bah]

or
if [ bah && bah ]



Relevant Pages

  • Re: Booming or Fuming? Are You Alive? Or Are You Fading Away?!
    ... The single .cmd file which is a Command Library ... consists of ONLY scripting code using ONLY ... every detail of convoluted shell scripting command syntax. ...
    (microsoft.public.win2000.cmdprompt.admin)
  • Re: Booming or Fuming? Are You Alive? Or Are You Fading Away?!
    ... The single .cmd file which is a Command Library ... consists of ONLY scripting code using ONLY ... every detail of convoluted shell scripting command syntax. ...
    (microsoft.public.windowsxp.perform_maintain)
  • Re: Any other words like right and left, east and west?
    ... For this speech activated scripting stuff, ... program to Dragon NaturallySpeaking called "Dragonfly". ... programs that enables Continuous Command Recognition. ...
    (alt.usage.english)
  • [COMMERCIAL] Ellié Computing Merge 2.1 for Linux
    ... You need to install the command line tools for that SCC. ... An ECMAScript compatible scripting engine is now included in ECMerge. ... Run on a differentiation, it will now export a textual ...
    (comp.os.linux.announce)
  • [ANN] Ellié Computing Merge 2.1
    ... You need to install the command line tools for that SCC. ... An ECMAScript compatible scripting engine is now included in ECMerge. ... Run on a differentiation, it will now export a textual ...
    (comp.software.shareware.announce)