Skip to main content

Posts

Showing posts with the label shell scripting

How wildcards work in Linux and Unix

Wildcards The * wildcard The character   *   is called a wildcard, and will match against none or more character(s) in a file (or directory) name. For example, in your   unixstuff directory, type % ls list* This will list all files in the current directory starting with   list.... Try typing % ls *list This will list all files in the current directory ending with   ....list The ? wildcard The character   ?   will match exactly one character. So   ?ouse   will match files like   house   and   mouse , but not   grouse .   Try typing % ls ?list  Filename conventions We should note here that a directory is merely a special type of file. So the rules and conventions for naming files apply also to directories. In naming files, characters with special meanings such as   / * & %   , should be avoided. Also, avoid using spaces within names. The safest way to name a f...

Shell Script: Find Number Of Arguments Passed

Many times , when we create shell scripts we try to do repetitive tasks through functions. Some functions take arguments & we have to check the no. of arguments that are passed to it. Each bash shell function has the following set of shell variables: [a] All function parameters or arguments can be accessed via  $1, $2, $3,..., $N . [b]  $*  or  $@  holds all parameters or arguments passed to the function. [c]  $#  holds the number of positional parameters passed to the function. [d] An array variable called  FUNCNAME  ontains the names of all shell functions currently in the execution call stack. Example Create a shell script as follows: #!/bin/bash # Purpose: Demo bash function # -----------------------------   ## Define a function called test() test(){   echo "Function name:  ${FUNCNAME}"   echo "The number of positional parameter : $#"   echo "All parameters or arguments pass...