Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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 : ' '`
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.