-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
12-globs.sh
54 lines (46 loc) · 1.43 KB
/
12-globs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# this creates some files for this example
# and cleans them up when the example is done
(
cd files
touch bear.txt bearable.txt bugbear.txt
)
trap 'rm files/*bear*.txt' EXIT
echo '
###########################################
## Example 12.1: #
## listing all files starting with "bear" #
###########################################
'
echo 'ls files/bear*:'
ls files/bear*
echo 'ls files/*.txt'
ls files/*.txt
echo "
##############################################
## Example 12.2: #
## filenames starting with a dot don't match #
##############################################
"
# all files with "bash" in your home directory
echo 'ls ~/*bash*'
ls ~/*bash* # no files with a . listed
# this will list .bashrc and .bash_profile,
# if you have them
echo 'ls ~/.bash*'
ls ~/.bash*
echo "
#################################################
## Example 12.3: #
## quote a * to pass a literal * as an argument #
#################################################
"
echo "let's try it without the quotes"
grep 22* files/lines.txt
echo "no results! this is because it's running this:"
echo grep 22* files/lines.txt
echo ''
echo "now let's try it with the quotes"
echo "$ grep '22*' files/lines.txt"
grep '22*' files/lines.txt
# the regular expression '22*' is kind of a silly one, this is
# similar to running `grep 2 files/lines.txt`