573
621
CLASS="PROGRAMLISTING"
574
622
> 1 #!/bin/bash
575
2 # list-glob.sh: Generating [list] in a for-loop, using "globbing"
580
7 # ^ Bash performs filename expansion
581
8 #+ on expressions that globbing recognizes.
583
10 ls -l "$file" # Lists all files in $PWD (current directory).
584
11 # Recall that the wild card character "*" matches every filename,
585
12 #+ however, in "globbing," it doesn't match dot-files.
587
14 # If the pattern matches no file, it is expanded to itself.
588
15 # To prevent this, set the nullglob option
589
16 #+ (shopt -s nullglob).
590
17 # Thanks, S.C.
595
22 for file in [jx]*
597
24 rm -f $file # Removes only files beginning with "j" or "x" in $PWD.
598
25 echo "Removed file \"$file\"".
623
2 # list-glob.sh: Generating [list] in a for-loop, using "globbing" ...
624
3 # Globbing = filename expansion.
629
8 # ^ Bash performs filename expansion
630
9 #+ on expressions that globbing recognizes.
632
11 ls -l "$file" # Lists all files in $PWD (current directory).
633
12 # Recall that the wild card character "*" matches every filename,
634
13 #+ however, in "globbing," it doesn't match dot-files.
636
15 # If the pattern matches no file, it is expanded to itself.
637
16 # To prevent this, set the nullglob option
638
17 #+ (shopt -s nullglob).
639
18 # Thanks, S.C.
644
23 for file in [jx]*
646
25 rm -f $file # Removes only files beginning with "j" or "x" in $PWD.
647
26 echo "Removed file \"$file\"".
854
903
7 for name in $(awk 'BEGIN{FS=":"}{print $1}' < "$PASSWORD_FILE" )
855
904
8 # Field separator = : ^^^^^^
856
905
9 # Print first field ^^^^^^^^
857
10 # Get input from password file ^^^^^^^^^^^^^^^^^
906
10 # Get input from password file /etc/passwd ^^^^^^^^^^^^^^^^^
859
908
12 echo "USER #$n = $name"
860
909
13 let "n += 1"
873
922
26 # ----------
874
923
27 # How is it that an ordinary user, or a script run by same,
875
924
28 #+ can read /etc/passwd? (Hint: Check the /etc/passwd file permissions.)
876
29 # Isn't this a security hole? Why or why not?</PRE
925
29 # Is this a security hole? Why or why not?</PRE
1100
1149
> 1 #!/bin/bash
1101
1150
2 # symlinks.sh: Lists symbolic links in a directory.
1103
4 OUTFILE=symlinks.list # save file
1152
4 OUTFILE=symlinks.list # save-file
1105
1154
6 directory=${1-`pwd`}
1106
1155
7 # Defaults to current working directory,
1373
SRC="common/note.png"
1385
HREF="internal.html#KEYWORDREF"
1398
> command block. However,
1399
these may, in certain contexts, be omitted by framing the
1400
command block within <A
1401
HREF="special-chars.html#CODEBLOCKREF"
1413
CLASS="PROGRAMLISTING"
1414
> 1 for((n=1; n<=10; n++))
1417
4 echo -n "* $n *"
1423
10 # * 1 ** 2 ** 3 ** 4 ** 5 ** 6 ** 7 ** 8 ** 9 ** 10 *
1424
11 # And, echo $? returns 0, so Bash does not register an error.
1430
17 # But, note that in a classic for-loop: for n in [list] ...
1431
18 #+ a terminal semicolon is required.
1433
20 for n in 1 2 3
1434
21 { echo -n "$n "; }
1438
25 # Thank you, YongYe, for pointing this out.</PRE
1558
1696
8 previous=$var1
1559
1697
9 [ "$var1" != end ] # Keeps track of what $var1 was previously.
1560
10 # Four conditions on "while", but only last one controls loop.
1698
10 # Four conditions on *while*, but only the final one controls loop.
1561
1699
11 # The *last* exit status is the one that counts.
1563
1701
13 echo "Input variable #1 (end to exit) "