Wild cards * and ?
The character * is a wildcard, and matches against one or more character(s) in a file (or directory) name.
Examples:
ls * will show all the files inside the current directory
ls *.s will show only the files which has .s extension
ls a* will show only the files which begin with a
ls ab* will show only the files which begin with ab
ls ab*.c will show only the files which begin with ab and have the .c extension
The character ? is also a wild cars which matches exactly one character in a file(or directory)name.
Examples:
ls ? will show only the files where their file name is one character long
ls bo? Will show only the files where their file name is 3 character long and starts with bo
Command line arguments
Consider the following command
cp ~/abc ~/Desktop
In this command there are two arguments. What if someone try to run this command without any of those arguments? the shell will probably give an error indicating arguments are missing.This point is crucial when someone uses commands which necessarily need arguments in their shell script. In that case they should run their shell script provided with those arguments.
Example :
Suppose our shell script name is comLineArgs.
Refresh memory on how to run it.
./comLineArgs
If someone needs to give the inputs to their shell scripts externally they can give them as command line arguments.
./comLine Args aaa bbb
The command line arguments which are used at a time can be also be accessed inside the sell script simply as variables.
Shell script name can be accessed as $0
Suppose there is n number of arguments. They can be accessed as $1, $2, $3……. $n
If someone needs to find the number of arguments $# can be used.
$* represents all the arguments.
Example Shell script describing how to access command line arguments.
echo "Total number of command line argument are $#"
echo "$0 is script name"
echo "$1 is first argument"
echo "$2 is second argument"
echo "All of them are :- $* or $@"
Input output redirection
Redirecting the output
> symbol is used to redirect the output of a command.
Example:
cat > file1
The above command creates a new file file1 or overwrites the existing file file1. Cat command reads the inputs given by the keyboard and redirects its output which is normally printed on the screen into the file1.
>> symbol is used to redirect the output of a command as well.
Example:
cat >> file1
Same thing as the > symbol but won’t overwrite the file adds more lines to the end of the file.
Redirecting the input
sort command sorts the contents of list1. Note that here inputs for the sort command are provided by the list1 file.
Pipes
Pipe is a temporary storage that output of a one command is stored and passes to another command as its input.
Example:
ls -l | wc -l
Output of ls command is given as input to wc command So that it will print number of files in current directory.