LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Closed Thread
  Search this Thread
Old 05-19-2010, 03:01 AM   #1
ruchika_sachdeva
LQ Newbie
 
Registered: May 2010
Posts: 2

Rep: Reputation: 0
need annotated explanation of the script !!


Hi i am new to linux and don't know about shell scripts. I need the detailed description of what each line of this shell script does.


1 #!/bin/bash
2 # makewhatis: create the whatis database
3
4 program=`basename $0`
5
6 # In case both /usr/man and /usr/share/man exist, the former is local
7 # and should be first.
8 # It is a bug to add /var/cache/man to DEFCATPATH.
9 dm=
10 for d in /usr/man /usr/share/man /usr/X11R6/man /usr/local/man
11 do
12 if [ -d $d ]; then
13 if [ x$dm = x ]; then dm=$d; else dm=$dm:$d; fi
14 fi
15 done
16 DEFMANPATH=$dm
17 dc=
18 for d in /usr/man/preformat /usr/man /usr/share/man/preformat /usr/share/man
19 do
20 if [ -d $d ]; then
21 if [ x$dc = x ]; then dc=$d; else dc=$dc:$d; fi
22 fi
23 done
24 DEFCATPATH=$dc
25
26 # make a single big /var/cache/man/whatis file,
27 DEFWHATISDIR=/var/cache/man
28 DEFWHATIS=$DEFWHATISDIR/whatis
29
30 AWK=/bin/awk
31
32 # Find a place for our temporary files.
33
34 if TMPFILE=$(mktemp /tmp/whatis.XXXXXX)
35 then
36
37 # make sure TMPFILE is deleted if program is killed or terminates
38 # (just delete this line if your shell doesnt know about trap)
39 trap "rm -rf $TMPFILE" 0
40 trap "rm -rf $TMPFILE; exit 255" 1 2 3 15
41
42 # default find arg: no directories, no empty files
43 findarg0="-type f -size +0"
44
45 topath=manpath
46
47 defmanpath=$DEFMANPATH
48 defcatpath=
49
50 if [ -n "$MANSECT" ]; then
51 sections=$MANSECT
52 else
53 sections=`$AWK '($1 == "MANSECT") { print $2 }' /etc/man.config`
54 if [ x"$sections" = x ]; then
55 sections="1:1p:8:2:3:3p:4:5:6:7:9:0p:tcl:n:l"
56 fi
57 fi
58 sections=`echo $sections | sed -e 's/:/ /g'`
59
60 whatisdb=$DEFWHATIS
61
62 for name in "$@"
63 do
64 if [ -n "$setsections" ]; then
65 setsections=
66 sections=$name
67 continue
68 fi
69 if [ -n "$setwhatis" ]; then
70 setwhatis=
71 whatisdb=$name
72 continue
73 fi
74 case $name in
75 --version|-V)
76 echo "$program from man-1.6f"
77 exit 0;;
78 -c) topath=catpath
79 defmanpath=
80 defcatpath=$DEFCATPATH
81 continue;;
82 -s) setsections=1
83 continue;;
84 -o) setwhatis=1
85 continue;;
86 -U) [ -f "$whatisdb" ] && findarg="-cnewer $whatisdb"
87 update=1
88 continue;;
89 -u) findarg="-ctime 0"
90 update=1
91 continue;;
92 -v) verbose=1
93 continue;;
94 -w) manpath=`man --path`
95 catpath=$manpath
96 continue;;
97 -*) echo "Usage: makewhatis [-s sections] [-u] [-v] [-w] [manpath] [-c [catpath]] [-o whatisdb]"
98 echo " This will build the whatis database for the man pages"
99 echo " found in manpath and the cat pages found in catpath."
100 echo " -s: sections (default: $sections)"
101 echo " -u: update database with pages added today"
102 echo " -U: update database with pages added since last makewhatis run"
103 echo " -v: verbose"
104 echo " -o: location of whatis database (default: $DEFWHATIS)"
105 echo " -w: use manpath obtained from \`man --path\`"
106 echo " [manpath]: man directories (default: $DEFMANPATH)"
107 echo " [catpath]: cat directories (default: the first existing"
108 echo " directory in $DEFCATPATH)"
109 exit;;
110 *) if [ -d $name ]
111 then
112 eval $topath="\$$topath":$name
113 else
114 echo "No such directory $name"
115 exit
116 fi;;
117 esac
118 done
119
120 manpath=`echo ${manpath-$defmanpath} | tr : ' '`
121 if [ x"$catpath" = x ]; then
122 for d in `echo $defcatpath | tr : ' '`
123 do
124 if [ -d $d ]; then catpath=$d; break; fi
125 done
126 fi
127 catpath=`echo ${catpath} | tr : ' '`
 
Old 05-19-2010, 03:06 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
I suggest you read the following:
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
Old 05-19-2010, 03:12 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,256

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
+1 to chrism01's suggestion ... maybe you could have even just googled bash
 
Old 05-19-2010, 08:19 AM   #4
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
And The LinuxCOmmand tutorial in my sig has a great, beginner-friendly bash scripting tutorial.
 
Old 05-19-2010, 08:23 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Per the LQ Rules, please do not post homework assignments verbatim. We're happy to assist if you have specific questions or have hit a stumbling point, however. Let us know what you've already tried and what references you have used (including class notes, books, and Google searches) and we'll do our best to help. Also, keep in mind that your instructor might also be an LQ member.

I cannot believe that you thought ANYONE would go line-by-line for 127 lines and explain what each one did!!!

Please feel free to start a new thread which meets the homework guidelines above.
 
  


Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need explanation how does the output comes????? immadisetty Programming 7 03-03-2010 04:11 AM
Error explanation igsen Linux - Newbie 2 04-08-2009 11:26 PM
Log explanation tekmann33 Linux - Newbie 2 07-25-2008 03:26 PM
Kernel Explanation FatLinux Mandriva 4 02-18-2004 07:37 PM
I Could Use An Explanation winger Linux - General 3 04-13-2002 11:32 PM


All times are GMT -5. The time now is 04:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration