| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 2 | <HTML |
| 3 | ><HEAD |
| 4 | ><TITLE |
| 5 | >File test operators</TITLE |
| 6 | ><META |
| 7 | NAME="GENERATOR" |
| 8 | CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+ |
| 9 | "><LINK |
| 10 | REL="HOME" |
| 11 | TITLE="Advanced Bash-Scripting Guide" |
| 12 | HREF="index.html"><LINK |
| 13 | REL="UP" |
| 14 | TITLE="Tests" |
| 15 | HREF="tests.html"><LINK |
| 16 | REL="PREVIOUS" |
| 17 | TITLE="Tests" |
| 18 | HREF="tests.html"><LINK |
| 19 | REL="NEXT" |
| 20 | TITLE="Other Comparison Operators" |
| 21 | HREF="comparison-ops.html"><META |
| 22 | HTTP-EQUIV="Content-Style-Type" |
| 23 | CONTENT="text/css"><LINK |
| 24 | REL="stylesheet" |
| 25 | HREF="common/kde-common.css" |
| 26 | TYPE="text/css"><META |
| 27 | HTTP-EQUIV="Content-Type" |
| 28 | CONTENT="text/html; charset=iso-8859-1"><META |
| 29 | HTTP-EQUIV="Content-Language" |
| 30 | CONTENT="en"><LINK |
| 31 | REL="stylesheet" |
| 32 | HREF="common/kde-localised.css" |
| 33 | TYPE="text/css" |
| 34 | TITLE="KDE-English"><LINK |
| 35 | REL="stylesheet" |
| 36 | HREF="common/kde-default.css" |
| 37 | TYPE="text/css" |
| 38 | TITLE="KDE-Default"></HEAD |
| 39 | ><BODY |
| 40 | CLASS="SECT1" |
| 41 | BGCOLOR="#FFFFFF" |
| 42 | TEXT="#000000" |
| 43 | LINK="#AA0000" |
| 44 | VLINK="#AA0055" |
| 45 | ALINK="#AA0000" |
| 46 | STYLE="font-family: sans-serif;" |
| 47 | ><DIV |
| 48 | CLASS="NAVHEADER" |
| 49 | ><TABLE |
| 50 | SUMMARY="Header navigation table" |
| 51 | WIDTH="100%" |
| 52 | BORDER="0" |
| 53 | CELLPADDING="0" |
| 54 | CELLSPACING="0" |
| 55 | ><TR |
| 56 | ><TH |
| 57 | COLSPAN="3" |
| 58 | ALIGN="center" |
| 59 | >Advanced Bash-Scripting Guide: An in-depth exploration of the art of shell scripting</TH |
| 60 | ></TR |
| 61 | ><TR |
| 62 | ><TD |
| 63 | WIDTH="10%" |
| 64 | ALIGN="left" |
| 65 | VALIGN="bottom" |
| 66 | ><A |
| 67 | HREF="tests.html" |
| 68 | ACCESSKEY="P" |
| 69 | >Prev</A |
| 70 | ></TD |
| 71 | ><TD |
| 72 | WIDTH="80%" |
| 73 | ALIGN="center" |
| 74 | VALIGN="bottom" |
| 75 | >Chapter 7. Tests</TD |
| 76 | ><TD |
| 77 | WIDTH="10%" |
| 78 | ALIGN="right" |
| 79 | VALIGN="bottom" |
| 80 | ><A |
| 81 | HREF="comparison-ops.html" |
| 82 | ACCESSKEY="N" |
| 83 | >Next</A |
| 84 | ></TD |
| 85 | ></TR |
| 86 | ></TABLE |
| 87 | ><HR |
| 88 | ALIGN="LEFT" |
| 89 | WIDTH="100%"></DIV |
| 90 | ><DIV |
| 91 | CLASS="SECT1" |
| 92 | ><H1 |
| 93 | CLASS="SECT1" |
| 94 | ><A |
| 95 | NAME="FTO" |
| 96 | ></A |
| 97 | >7.2. File test operators</H1 |
| 98 | ><DIV |
| 99 | CLASS="VARIABLELIST" |
| 100 | ><P |
| 101 | ><B |
| 102 | ><A |
| 103 | NAME="RTIF" |
| 104 | ></A |
| 105 | >Returns true if...</B |
| 106 | ></P |
| 107 | ><DL |
| 108 | ><DT |
| 109 | ><SPAN |
| 110 | CLASS="TOKEN" |
| 111 | >-e</SPAN |
| 112 | ></DT |
| 113 | ><DD |
| 114 | ><P |
| 115 | >file exists</P |
| 116 | ></DD |
| 117 | ><DT |
| 118 | ><SPAN |
| 119 | CLASS="TOKEN" |
| 120 | >-a</SPAN |
| 121 | ></DT |
| 122 | ><DD |
| 123 | ><P |
| 124 | >file exists</P |
| 125 | ><P |
| 126 | >This is identical in effect to <SPAN |
| 127 | CLASS="TOKEN" |
| 128 | >-e</SPAN |
| 129 | >. |
| 130 | It has been <SPAN |
| 131 | CLASS="QUOTE" |
| 132 | >"deprecated,"</SPAN |
| 133 | > |
| 134 | |
| 135 | <A |
| 136 | NAME="AEN3289" |
| 137 | HREF="#FTN.AEN3289" |
| 138 | >[1]</A |
| 139 | > |
| 140 | |
| 141 | and its use is |
| 142 | discouraged.</P |
| 143 | ></DD |
| 144 | ><DT |
| 145 | ><A |
| 146 | NAME="REGULARFILE" |
| 147 | ></A |
| 148 | ><SPAN |
| 149 | CLASS="TOKEN" |
| 150 | >-f</SPAN |
| 151 | ></DT |
| 152 | ><DD |
| 153 | ><P |
| 154 | >file is a <TT |
| 155 | CLASS="REPLACEABLE" |
| 156 | ><I |
| 157 | >regular</I |
| 158 | ></TT |
| 159 | > |
| 160 | file (not a directory or <A |
| 161 | HREF="devproc.html#DEVFILEREF" |
| 162 | >device |
| 163 | file</A |
| 164 | >)</P |
| 165 | ></DD |
| 166 | ><DT |
| 167 | ><SPAN |
| 168 | CLASS="TOKEN" |
| 169 | >-s</SPAN |
| 170 | ></DT |
| 171 | ><DD |
| 172 | ><P |
| 173 | >file is not zero size</P |
| 174 | ></DD |
| 175 | ><DT |
| 176 | ><SPAN |
| 177 | CLASS="TOKEN" |
| 178 | >-d</SPAN |
| 179 | ></DT |
| 180 | ><DD |
| 181 | ><P |
| 182 | >file is a directory</P |
| 183 | ></DD |
| 184 | ><DT |
| 185 | ><SPAN |
| 186 | CLASS="TOKEN" |
| 187 | >-b</SPAN |
| 188 | ></DT |
| 189 | ><DD |
| 190 | ><P |
| 191 | >file is a <A |
| 192 | HREF="devproc.html#BLOCKDEVREF" |
| 193 | >block |
| 194 | device</A |
| 195 | ></P |
| 196 | ><P |
| 197 | ><A |
| 198 | NAME="BLOCKDEVTEST" |
| 199 | ></A |
| 200 | ></P |
| 201 | ></DD |
| 202 | ><DT |
| 203 | ><SPAN |
| 204 | CLASS="TOKEN" |
| 205 | >-c</SPAN |
| 206 | ></DT |
| 207 | ><DD |
| 208 | ><P |
| 209 | ><A |
| 210 | NAME="CHARDEVTEST" |
| 211 | ></A |
| 212 | >file is a <A |
| 213 | HREF="devproc.html#CHARDEVREF" |
| 214 | >character device</A |
| 215 | ></P |
| 216 | ><P |
| 217 | ><TABLE |
| 218 | BORDER="0" |
| 219 | BGCOLOR="#E0E0E0" |
| 220 | WIDTH="90%" |
| 221 | ><TR |
| 222 | ><TD |
| 223 | ><PRE |
| 224 | CLASS="PROGRAMLISTING" |
| 225 | > 1 device0="/dev/sda2" # / (root directory) |
| 226 | 2 if [ -b "$device0" ] |
| 227 | 3 then |
| 228 | 4 echo "$device0 is a block device." |
| 229 | 5 fi |
| 230 | 6 |
| 231 | 7 # /dev/sda2 is a block device. |
| 232 | 8 |
| 233 | 9 |
| 234 | 10 |
| 235 | 11 device1="/dev/ttyS1" # PCMCIA modem card. |
| 236 | 12 if [ -c "$device1" ] |
| 237 | 13 then |
| 238 | 14 echo "$device1 is a character device." |
| 239 | 15 fi |
| 240 | 16 |
| 241 | 17 # /dev/ttyS1 is a character device.</PRE |
| 242 | ></TD |
| 243 | ></TR |
| 244 | ></TABLE |
| 245 | ></P |
| 246 | ></DD |
| 247 | ><DT |
| 248 | ><SPAN |
| 249 | CLASS="TOKEN" |
| 250 | >-p</SPAN |
| 251 | ></DT |
| 252 | ><DD |
| 253 | ><P |
| 254 | >file is a <A |
| 255 | HREF="special-chars.html#PIPEREF" |
| 256 | >pipe</A |
| 257 | ></P |
| 258 | ><P |
| 259 | ><TABLE |
| 260 | BORDER="0" |
| 261 | BGCOLOR="#E0E0E0" |
| 262 | WIDTH="90%" |
| 263 | ><TR |
| 264 | ><TD |
| 265 | ><PRE |
| 266 | CLASS="PROGRAMLISTING" |
| 267 | > 1 function show_input_type() |
| 268 | 2 { |
| 269 | 3 [ -p /dev/fd/0 ] && echo PIPE || echo STDIN |
| 270 | 4 } |
| 271 | 5 |
| 272 | 6 show_input_type "Input" # STDIN |
| 273 | 7 echo "Input" | show_input_type # PIPE |
| 274 | 8 |
| 275 | 9 # This example courtesy of Carl Anderson.</PRE |
| 276 | ></TD |
| 277 | ></TR |
| 278 | ></TABLE |
| 279 | ></P |
| 280 | ></DD |
| 281 | ><DT |
| 282 | ><SPAN |
| 283 | CLASS="TOKEN" |
| 284 | >-h</SPAN |
| 285 | ></DT |
| 286 | ><DD |
| 287 | ><P |
| 288 | >file is a <A |
| 289 | HREF="external.html#SYMLINKREF" |
| 290 | >symbolic |
| 291 | link</A |
| 292 | ></P |
| 293 | ></DD |
| 294 | ><DT |
| 295 | ><SPAN |
| 296 | CLASS="TOKEN" |
| 297 | >-L</SPAN |
| 298 | ></DT |
| 299 | ><DD |
| 300 | ><P |
| 301 | >file is a symbolic link</P |
| 302 | ></DD |
| 303 | ><DT |
| 304 | ><SPAN |
| 305 | CLASS="TOKEN" |
| 306 | >-S</SPAN |
| 307 | ></DT |
| 308 | ><DD |
| 309 | ><P |
| 310 | >file is a <A |
| 311 | HREF="devproc.html#SOCKETREF" |
| 312 | >socket</A |
| 313 | ></P |
| 314 | ></DD |
| 315 | ><DT |
| 316 | ><SPAN |
| 317 | CLASS="TOKEN" |
| 318 | >-t</SPAN |
| 319 | ></DT |
| 320 | ><DD |
| 321 | ><P |
| 322 | ><A |
| 323 | NAME="TERMTEST" |
| 324 | ></A |
| 325 | >file (<A |
| 326 | HREF="io-redirection.html#FDREF" |
| 327 | >descriptor</A |
| 328 | >) is |
| 329 | associated with a terminal device</P |
| 330 | ><P |
| 331 | >This test option <A |
| 332 | HREF="miscellany.html#II2TEST" |
| 333 | > may be used |
| 334 | to check</A |
| 335 | > whether the <TT |
| 336 | CLASS="FILENAME" |
| 337 | >stdin</TT |
| 338 | > |
| 339 | <TT |
| 340 | CLASS="USERINPUT" |
| 341 | ><B |
| 342 | >[ -t 0 ]</B |
| 343 | ></TT |
| 344 | > or |
| 345 | <TT |
| 346 | CLASS="FILENAME" |
| 347 | >stdout</TT |
| 348 | > <TT |
| 349 | CLASS="USERINPUT" |
| 350 | ><B |
| 351 | >[ -t 1 ]</B |
| 352 | ></TT |
| 353 | > |
| 354 | in a given script is a terminal.</P |
| 355 | ></DD |
| 356 | ><DT |
| 357 | ><SPAN |
| 358 | CLASS="TOKEN" |
| 359 | >-r</SPAN |
| 360 | ></DT |
| 361 | ><DD |
| 362 | ><P |
| 363 | >file has read permission (<SPAN |
| 364 | CLASS="emphasis" |
| 365 | ><I |
| 366 | CLASS="EMPHASIS" |
| 367 | >for the |
| 368 | user running the test</I |
| 369 | ></SPAN |
| 370 | >)</P |
| 371 | ></DD |
| 372 | ><DT |
| 373 | ><SPAN |
| 374 | CLASS="TOKEN" |
| 375 | >-w</SPAN |
| 376 | ></DT |
| 377 | ><DD |
| 378 | ><P |
| 379 | >file has write permission (for the user running |
| 380 | the test)</P |
| 381 | ></DD |
| 382 | ><DT |
| 383 | ><SPAN |
| 384 | CLASS="TOKEN" |
| 385 | >-x</SPAN |
| 386 | ></DT |
| 387 | ><DD |
| 388 | ><P |
| 389 | >file has execute permission (for the user running |
| 390 | the test)</P |
| 391 | ></DD |
| 392 | ><DT |
| 393 | ><SPAN |
| 394 | CLASS="TOKEN" |
| 395 | >-g</SPAN |
| 396 | ></DT |
| 397 | ><DD |
| 398 | ><P |
| 399 | >set-group-id (sgid) flag set on file or directory</P |
| 400 | ><P |
| 401 | >If a directory has the <TT |
| 402 | CLASS="REPLACEABLE" |
| 403 | ><I |
| 404 | >sgid</I |
| 405 | ></TT |
| 406 | > |
| 407 | flag set, then a file created within that directory belongs |
| 408 | to the group that owns the directory, not necessarily to |
| 409 | the group of the user who created the file. This may be |
| 410 | useful for a directory shared by a workgroup.</P |
| 411 | ></DD |
| 412 | ><DT |
| 413 | ><SPAN |
| 414 | CLASS="TOKEN" |
| 415 | >-u</SPAN |
| 416 | ></DT |
| 417 | ><DD |
| 418 | ><P |
| 419 | ><A |
| 420 | NAME="SUIDREF" |
| 421 | ></A |
| 422 | ></P |
| 423 | ><P |
| 424 | >set-user-id (suid) flag set on file</P |
| 425 | ><P |
| 426 | >A binary owned by <I |
| 427 | CLASS="FIRSTTERM" |
| 428 | >root</I |
| 429 | > |
| 430 | with <TT |
| 431 | CLASS="REPLACEABLE" |
| 432 | ><I |
| 433 | >set-user-id</I |
| 434 | ></TT |
| 435 | > flag set |
| 436 | runs with <I |
| 437 | CLASS="FIRSTTERM" |
| 438 | >root</I |
| 439 | > privileges, even |
| 440 | when an ordinary user invokes it. |
| 441 | |
| 442 | <A |
| 443 | NAME="AEN3400" |
| 444 | HREF="#FTN.AEN3400" |
| 445 | >[2]</A |
| 446 | > |
| 447 | |
| 448 | This is useful for executables (such as |
| 449 | <B |
| 450 | CLASS="COMMAND" |
| 451 | >pppd</B |
| 452 | > and <B |
| 453 | CLASS="COMMAND" |
| 454 | >cdrecord</B |
| 455 | >) |
| 456 | that need to access system hardware. Lacking the |
| 457 | <I |
| 458 | CLASS="FIRSTTERM" |
| 459 | >suid</I |
| 460 | > flag, these binaries could not |
| 461 | be invoked by a <I |
| 462 | CLASS="FIRSTTERM" |
| 463 | >non-root</I |
| 464 | > user.</P |
| 465 | ><P |
| 466 | > <TABLE |
| 467 | BORDER="0" |
| 468 | BGCOLOR="#E0E0E0" |
| 469 | WIDTH="90%" |
| 470 | ><TR |
| 471 | ><TD |
| 472 | ><PRE |
| 473 | CLASS="SCREEN" |
| 474 | > <TT |
| 475 | CLASS="COMPUTEROUTPUT" |
| 476 | >-rwsr-xr-t 1 root 178236 Oct 2 2000 /usr/sbin/pppd</TT |
| 477 | > |
| 478 | </PRE |
| 479 | ></TD |
| 480 | ></TR |
| 481 | ></TABLE |
| 482 | > |
| 483 | </P |
| 484 | ><P |
| 485 | >A file with the <TT |
| 486 | CLASS="REPLACEABLE" |
| 487 | ><I |
| 488 | >suid</I |
| 489 | ></TT |
| 490 | > |
| 491 | flag set shows an <I |
| 492 | CLASS="FIRSTTERM" |
| 493 | >s</I |
| 494 | > in its |
| 495 | permissions.</P |
| 496 | ></DD |
| 497 | ><DT |
| 498 | ><SPAN |
| 499 | CLASS="TOKEN" |
| 500 | >-k</SPAN |
| 501 | ></DT |
| 502 | ><DD |
| 503 | ><P |
| 504 | ><TT |
| 505 | CLASS="REPLACEABLE" |
| 506 | ><I |
| 507 | >sticky bit</I |
| 508 | ></TT |
| 509 | > set</P |
| 510 | ><P |
| 511 | >Commonly known as the <I |
| 512 | CLASS="FIRSTTERM" |
| 513 | >sticky bit,</I |
| 514 | > |
| 515 | the <I |
| 516 | CLASS="FIRSTTERM" |
| 517 | >save-text-mode</I |
| 518 | > flag is a special |
| 519 | type of file permission. If a file has this flag set, |
| 520 | that file will be kept in cache memory, for quicker access. |
| 521 | <A |
| 522 | NAME="AEN3423" |
| 523 | HREF="#FTN.AEN3423" |
| 524 | >[3]</A |
| 525 | > |
| 526 | If set on a directory, it restricts write permission. |
| 527 | Setting the sticky bit adds a <I |
| 528 | CLASS="FIRSTTERM" |
| 529 | >t</I |
| 530 | > |
| 531 | to the permissions on the file or directory listing. |
| 532 | This restricts altering or deleting specific files |
| 533 | in that directory to the owner of those files.</P |
| 534 | ><P |
| 535 | > <TABLE |
| 536 | BORDER="0" |
| 537 | BGCOLOR="#E0E0E0" |
| 538 | WIDTH="90%" |
| 539 | ><TR |
| 540 | ><TD |
| 541 | ><PRE |
| 542 | CLASS="SCREEN" |
| 543 | > <TT |
| 544 | CLASS="COMPUTEROUTPUT" |
| 545 | >drwxrwxrwt 7 root 1024 May 19 21:26 tmp/</TT |
| 546 | > |
| 547 | </PRE |
| 548 | ></TD |
| 549 | ></TR |
| 550 | ></TABLE |
| 551 | > |
| 552 | </P |
| 553 | ><P |
| 554 | >If a user does not own a directory that has the sticky |
| 555 | bit set, but has write permission in that directory, she |
| 556 | can only delete those files that she owns in it. This |
| 557 | keeps users from inadvertently overwriting or deleting |
| 558 | each other's files in a publicly accessible directory, |
| 559 | such as <TT |
| 560 | CLASS="FILENAME" |
| 561 | >/tmp</TT |
| 562 | >. |
| 563 | (The <I |
| 564 | CLASS="FIRSTTERM" |
| 565 | >owner</I |
| 566 | > of the directory or |
| 567 | <I |
| 568 | CLASS="FIRSTTERM" |
| 569 | >root</I |
| 570 | > can, of course, delete or |
| 571 | rename files there.)</P |
| 572 | ></DD |
| 573 | ><DT |
| 574 | ><SPAN |
| 575 | CLASS="TOKEN" |
| 576 | >-O</SPAN |
| 577 | ></DT |
| 578 | ><DD |
| 579 | ><P |
| 580 | >you are owner of file</P |
| 581 | ></DD |
| 582 | ><DT |
| 583 | ><SPAN |
| 584 | CLASS="TOKEN" |
| 585 | >-G</SPAN |
| 586 | ></DT |
| 587 | ><DD |
| 588 | ><P |
| 589 | >group-id of file same as yours</P |
| 590 | ></DD |
| 591 | ><DT |
| 592 | ><SPAN |
| 593 | CLASS="TOKEN" |
| 594 | >-N</SPAN |
| 595 | ></DT |
| 596 | ><DD |
| 597 | ><P |
| 598 | >file modified since it was last read</P |
| 599 | ></DD |
| 600 | ><DT |
| 601 | ><SPAN |
| 602 | CLASS="TOKEN" |
| 603 | >f1 -nt f2</SPAN |
| 604 | ></DT |
| 605 | ><DD |
| 606 | ><P |
| 607 | >file <TT |
| 608 | CLASS="REPLACEABLE" |
| 609 | ><I |
| 610 | >f1</I |
| 611 | ></TT |
| 612 | > is newer than |
| 613 | <TT |
| 614 | CLASS="REPLACEABLE" |
| 615 | ><I |
| 616 | >f2</I |
| 617 | ></TT |
| 618 | ></P |
| 619 | ></DD |
| 620 | ><DT |
| 621 | ><SPAN |
| 622 | CLASS="TOKEN" |
| 623 | >f1 -ot f2</SPAN |
| 624 | ></DT |
| 625 | ><DD |
| 626 | ><P |
| 627 | >file <TT |
| 628 | CLASS="REPLACEABLE" |
| 629 | ><I |
| 630 | >f1</I |
| 631 | ></TT |
| 632 | > is older than |
| 633 | <TT |
| 634 | CLASS="REPLACEABLE" |
| 635 | ><I |
| 636 | >f2</I |
| 637 | ></TT |
| 638 | ></P |
| 639 | ></DD |
| 640 | ><DT |
| 641 | ><SPAN |
| 642 | CLASS="TOKEN" |
| 643 | >f1 -ef f2</SPAN |
| 644 | ></DT |
| 645 | ><DD |
| 646 | ><P |
| 647 | >files <TT |
| 648 | CLASS="REPLACEABLE" |
| 649 | ><I |
| 650 | >f1</I |
| 651 | ></TT |
| 652 | > and |
| 653 | <TT |
| 654 | CLASS="REPLACEABLE" |
| 655 | ><I |
| 656 | >f2</I |
| 657 | ></TT |
| 658 | > are hard links to the same |
| 659 | file</P |
| 660 | ></DD |
| 661 | ><DT |
| 662 | ><SPAN |
| 663 | CLASS="TOKEN" |
| 664 | >!</SPAN |
| 665 | ></DT |
| 666 | ><DD |
| 667 | ><P |
| 668 | ><SPAN |
| 669 | CLASS="QUOTE" |
| 670 | >"not"</SPAN |
| 671 | > -- reverses the sense of the |
| 672 | tests above (returns true if condition absent).</P |
| 673 | ></DD |
| 674 | ></DL |
| 675 | ></DIV |
| 676 | ><DIV |
| 677 | CLASS="EXAMPLE" |
| 678 | ><HR><A |
| 679 | NAME="BROKENLINK" |
| 680 | ></A |
| 681 | ><P |
| 682 | ><B |
| 683 | >Example 7-4. Testing for broken links</B |
| 684 | ></P |
| 685 | ><TABLE |
| 686 | BORDER="0" |
| 687 | BGCOLOR="#E0E0E0" |
| 688 | WIDTH="100%" |
| 689 | ><TR |
| 690 | ><TD |
| 691 | ><PRE |
| 692 | CLASS="PROGRAMLISTING" |
| 693 | > 1 #!/bin/bash |
| 694 | 2 # broken-link.sh |
| 695 | 3 # Written by Lee bigelow <[email protected]> |
| 696 | 4 # Used in ABS Guide with permission. |
| 697 | 5 |
| 698 | 6 # A pure shell script to find dead symlinks and output them quoted |
| 699 | 7 #+ so they can be fed to xargs and dealt with :) |
| 700 | 8 #+ eg. sh broken-link.sh /somedir /someotherdir|xargs rm |
| 701 | 9 # |
| 702 | 10 # This, however, is a better method: |
| 703 | 11 # |
| 704 | 12 # find "somedir" -type l -print0|\ |
| 705 | 13 # xargs -r0 file|\ |
| 706 | 14 # grep "broken symbolic"| |
| 707 | 15 # sed -e 's/^\|: *broken symbolic.*$/"/g' |
| 708 | 16 # |
| 709 | 17 #+ but that wouldn't be pure Bash, now would it. |
| 710 | 18 # Caution: beware the /proc file system and any circular links! |
| 711 | 19 ################################################################ |
| 712 | 20 |
| 713 | 21 |
| 714 | 22 # If no args are passed to the script set directories-to-search |
| 715 | 23 #+ to current directory. Otherwise set the directories-to-search |
| 716 | 24 #+ to the args passed. |
| 717 | 25 ###################### |
| 718 | 26 |
| 719 | 27 [ $# -eq 0 ] && directorys=`pwd` || directorys=$@ |
| 720 | 28 |
| 721 | 29 |
| 722 | 30 # Setup the function linkchk to check the directory it is passed |
| 723 | 31 #+ for files that are links and don't exist, then print them quoted. |
| 724 | 32 # If one of the elements in the directory is a subdirectory then |
| 725 | 33 #+ send that subdirectory to the linkcheck function. |
| 726 | 34 ########## |
| 727 | 35 |
| 728 | 36 linkchk () { |
| 729 | 37 for element in $1/*; do |
| 730 | 38 [ -h "$element" -a ! -e "$element" ] && echo \"$element\" |
| 731 | 39 [ -d "$element" ] && linkchk $element |
| 732 | 40 # Of course, '-h' tests for symbolic link, '-d' for directory. |
| 733 | 41 done |
| 734 | 42 } |
| 735 | 43 |
| 736 | 44 # Send each arg that was passed to the script to the linkchk() function |
| 737 | 45 #+ if it is a valid directoy. If not, then print the error message |
| 738 | 46 #+ and usage info. |
| 739 | 47 ################## |
| 740 | 48 for directory in $directorys; do |
| 741 | 49 if [ -d $directory ] |
| 742 | 50 then linkchk $directory |
| 743 | 51 else |
| 744 | 52 echo "$directory is not a directory" |
| 745 | 53 echo "Usage: $0 dir1 dir2 ..." |
| 746 | 54 fi |
| 747 | 55 done |
| 748 | 56 |
| 749 | 57 exit $?</PRE |
| 750 | ></TD |
| 751 | ></TR |
| 752 | ></TABLE |
| 753 | ><HR></DIV |
| 754 | ><P |
| 755 | ><A |
| 756 | HREF="zeros.html#COOKIES" |
| 757 | >Example 31-1</A |
| 758 | >, <A |
| 759 | HREF="loops.html#BINGREP" |
| 760 | >Example 11-8</A |
| 761 | >, |
| 762 | <A |
| 763 | HREF="loops.html#FILEINFO" |
| 764 | >Example 11-3</A |
| 765 | >, <A |
| 766 | HREF="zeros.html#RAMDISK" |
| 767 | >Example 31-3</A |
| 768 | >, and <A |
| 769 | HREF="contributed-scripts.html#MAILFORMAT" |
| 770 | >Example A-1</A |
| 771 | > also illustrate uses of the file test |
| 772 | operators.</P |
| 773 | ></DIV |
| 774 | ><H3 |
| 775 | CLASS="FOOTNOTES" |
| 776 | >Notes</H3 |
| 777 | ><TABLE |
| 778 | BORDER="0" |
| 779 | CLASS="FOOTNOTES" |
| 780 | WIDTH="100%" |
| 781 | ><TR |
| 782 | ><TD |
| 783 | ALIGN="LEFT" |
| 784 | VALIGN="TOP" |
| 785 | WIDTH="5%" |
| 786 | ><A |
| 787 | NAME="FTN.AEN3289" |
| 788 | HREF="fto.html#AEN3289" |
| 789 | >[1]</A |
| 790 | ></TD |
| 791 | ><TD |
| 792 | ALIGN="LEFT" |
| 793 | VALIGN="TOP" |
| 794 | WIDTH="95%" |
| 795 | ><P |
| 796 | > Per the 1913 edition of <SPAN |
| 797 | CLASS="emphasis" |
| 798 | ><I |
| 799 | CLASS="EMPHASIS" |
| 800 | >Webster's |
| 801 | Dictionary</I |
| 802 | ></SPAN |
| 803 | >: |
| 804 | <TABLE |
| 805 | BORDER="0" |
| 806 | BGCOLOR="#E0E0E0" |
| 807 | WIDTH="90%" |
| 808 | ><TR |
| 809 | ><TD |
| 810 | ><PRE |
| 811 | CLASS="PROGRAMLISTING" |
| 812 | > 1 Deprecate |
| 813 | 2 ... |
| 814 | 3 |
| 815 | 4 To pray against, as an evil; |
| 816 | 5 to seek to avert by prayer; |
| 817 | 6 to desire the removal of; |
| 818 | 7 to seek deliverance from; |
| 819 | 8 to express deep regret for; |
| 820 | 9 to disapprove of strongly.</PRE |
| 821 | ></TD |
| 822 | ></TR |
| 823 | ></TABLE |
| 824 | > |
| 825 | </P |
| 826 | ></TD |
| 827 | ></TR |
| 828 | ><TR |
| 829 | ><TD |
| 830 | ALIGN="LEFT" |
| 831 | VALIGN="TOP" |
| 832 | WIDTH="5%" |
| 833 | ><A |
| 834 | NAME="FTN.AEN3400" |
| 835 | HREF="fto.html#AEN3400" |
| 836 | >[2]</A |
| 837 | ></TD |
| 838 | ><TD |
| 839 | ALIGN="LEFT" |
| 840 | VALIGN="TOP" |
| 841 | WIDTH="95%" |
| 842 | ><P |
| 843 | >Be aware that <I |
| 844 | CLASS="FIRSTTERM" |
| 845 | >suid</I |
| 846 | > |
| 847 | binaries may open security holes. The |
| 848 | <I |
| 849 | CLASS="FIRSTTERM" |
| 850 | >suid</I |
| 851 | > flag has no effect on |
| 852 | shell scripts.</P |
| 853 | ></TD |
| 854 | ></TR |
| 855 | ><TR |
| 856 | ><TD |
| 857 | ALIGN="LEFT" |
| 858 | VALIGN="TOP" |
| 859 | WIDTH="5%" |
| 860 | ><A |
| 861 | NAME="FTN.AEN3423" |
| 862 | HREF="fto.html#AEN3423" |
| 863 | >[3]</A |
| 864 | ></TD |
| 865 | ><TD |
| 866 | ALIGN="LEFT" |
| 867 | VALIGN="TOP" |
| 868 | WIDTH="95%" |
| 869 | ><P |
| 870 | >On Linux systems, the sticky |
| 871 | bit is no longer used for files, only on |
| 872 | directories.</P |
| 873 | ></TD |
| 874 | ></TR |
| 875 | ></TABLE |
| 876 | ><DIV |
| 877 | CLASS="NAVFOOTER" |
| 878 | ><HR |
| 879 | ALIGN="LEFT" |
| 880 | WIDTH="100%"><TABLE |
| 881 | SUMMARY="Footer navigation table" |
| 882 | WIDTH="100%" |
| 883 | BORDER="0" |
| 884 | CELLPADDING="0" |
| 885 | CELLSPACING="0" |
| 886 | ><TR |
| 887 | ><TD |
| 888 | WIDTH="33%" |
| 889 | ALIGN="left" |
| 890 | VALIGN="top" |
| 891 | ><A |
| 892 | HREF="tests.html" |
| 893 | ACCESSKEY="P" |
| 894 | >Prev</A |
| 895 | ></TD |
| 896 | ><TD |
| 897 | WIDTH="34%" |
| 898 | ALIGN="center" |
| 899 | VALIGN="top" |
| 900 | ><A |
| 901 | HREF="index.html" |
| 902 | ACCESSKEY="H" |
| 903 | >Home</A |
| 904 | ></TD |
| 905 | ><TD |
| 906 | WIDTH="33%" |
| 907 | ALIGN="right" |
| 908 | VALIGN="top" |
| 909 | ><A |
| 910 | HREF="comparison-ops.html" |
| 911 | ACCESSKEY="N" |
| 912 | >Next</A |
| 913 | ></TD |
| 914 | ></TR |
| 915 | ><TR |
| 916 | ><TD |
| 917 | WIDTH="33%" |
| 918 | ALIGN="left" |
| 919 | VALIGN="top" |
| 920 | >Tests</TD |
| 921 | ><TD |
| 922 | WIDTH="34%" |
| 923 | ALIGN="center" |
| 924 | VALIGN="top" |
| 925 | ><A |
| 926 | HREF="tests.html" |
| 927 | ACCESSKEY="U" |
| 928 | >Up</A |
| 929 | ></TD |
| 930 | ><TD |
| 931 | WIDTH="33%" |
| 932 | ALIGN="right" |
| 933 | VALIGN="top" |
| 934 | >Other Comparison Operators</TD |
| 935 | ></TR |
| 936 | ></TABLE |
| 937 | ></DIV |
| 938 | ></BODY |
| 939 | ></HTML |
| 940 | > |