The execution of scripts is made versatile by the ability to run a script based on arguments supplied on the command line. In this way, the operation of the script varies depending on what arguments are given to the script. The shell automatically assigns special variable names, called positional parameters, to each argument supplied to […]
Shell Scripting
Bash if loop examples (if then fi, if then elif fi, if then else fi)
The if Statement The if statement allows you to specify courses of action to be taken in a shell script, depending on the success or failure of some command. It is a conditional statement that allows a test before performing another statement. The syntax for the simplest form is: if [ condition ] then block_of_statements […]
What is the purpose of .bash_profile file under User Home Directory In Linux
What is the purpose of ~/.bash_profile file Apart from having a home directory to create and store files, users need an environment that gives them access to the tools and resources. When a user logs in to a system, the user’s work environment is determined by the initialization files. These initialization files are defined by […]
Understanding Variables in Bash Shell Under Linux
What are Variables? A variable is a temporary storage area in memory that is either set by the user, shell, system, or any program that loads another program. There are two categories of variables: The environment variables are valid for the duration of the session. The shell variables apply only to the current instance of […]
How to use command redirection under Linux
Shell metacharacters Shell metacharacters are specific characters, generally symbols, that have special meaning within the shell. The metacharacters supported in bash are listed as follows: | : Sends the output of the command to the left as the input to the command on the right of the symbol & : Runs the process in the […]
How to use shell expansions for generating shell tokens under Linux
Shell Expansions While working in a shell, sets or ranges of information are often repeated. Shell expansion helps generate a large number of shell tokens using compact syntaxes. The expansion is performed on the command line after the command is split into tokens. Of the many expansions available, the path name, file name, and brace […]
How to use command line shell functions in Linux
Functions, a powerful feature of shell programming, is a group of commands organized by common functionality. These easy-to-manage units, when called return a single value, and do not output anything. Using a function involves two steps: 1. Defining the function 2. Invoking the function Shell function Vs shell alias Shell functions and aliases are different […]
How to use shell aliases in Linux
What is an alias An alias is a shorthand shell notation that allows you to customize and abbreviate commands. Aliases are available in all shells. A common syntax to define an alias on command line is as follows: $ alias name=command_string If the first word on the command line is an alias, the shell replaces […]
Examples of creating command alias in different shells
Alias for commands lets you define your own short easy to remember command shortcuts. Below are some examples of defining command aliases permanently into the different shells like bash, ksh and sh. You can also define aliases on command line, but they will not persist after you change the shell or logout of the shell. […]
Introduction to sed (Stream Editor) : Useful sed Command Examples
Introduction to the sed Editor The term sed stands for stream editor. Sed can take its input from standard in, apply the requested edits on the stream, and automatically put the results to standard out. The sed syntax allows for an input file to be specified on the command line. You do not need to […]