You've already been introduced to; grep, redirection, variables.
Now, explaining command line variables. They are numbered from left to right as you type them. If you have three arguments, then you have variables $1 $2 $3
$@ means all command line arguments
$# means the number of arguments
In this example we use the case statement to determine which commands to run. And this is your first viewing of case in this study
The information we give case is $# which is the total count of our arguments. Valid matches, (true conditions), are 1 to 3. If we don't give case a number between 1 to 3 arguments, then * is true and it echos an error and does nothing.
Have a look and see what you can learn and derive.
Code: Select all
#!/bin/bash
main() {
var
dofind "$@"
}
var() {
file="/var/log/updatedbd"
}
dofind() {
case $# in
1)
<$file grep --ignore-case "$1"
;;
2)
<$file grep --ignore-case "$1" \
| grep --ignore-case "$2"
;;
3)
<$file grep --ignore-case "$1" \
| grep --ignore-case "$2" \
| grep --ignore-case "$3"
;;
*)
echo "Incorrect number of arguments"
;;
esac
}
main "$@"
findf is for finding files
findd is for finding directories
updatedb is for building the databases
findf means find files
findd means find directories
First run updatedb to build your database, then run findd and see if you can locate the directories containing pixmaps and icons.
Remembering, we don't want to type too much, if you want the output of a line, just double-click it to select it and shift+insert or push mouse button to paste the text on your command line or into an editor. Useful when writing scripts to make sure you don't make a typo.
Suppose you want to change to a directory in your output, type cd (space) in the command line, then paste the directory to the command line and hit enter.
There are many ways to keep from typing too much when using the command line, in time we will learn more and more
~
Chapter 15 - Find scripts