Bash – Override Builtin Commands using Functions

Bash – Override Commands

Bash – Override Commands : In this Bash Tutorial, we shall learn to override an inbuilt command using Bash Functions.

We may override commands in bash by creating a function with the same name as the command we would like to override. For example to override ps  command, you have to create a function with name ps .

This could be helpful in  scenarios like you use a command with certain options, and you do not like to provide the whole command with options several times in your script. So you may override the command for command with options. Now let us learn how overriding commands could be done in Bash Shell Scripting.

 

Example – Bash – Override Command

In this example, we shall try overriding ls  command for ls -ltr .

 

Example – 2 – Bash – Override Command

In this example, we shall try overriding echo  command, and add time stamp in from of the argument to echo  command.

 

Conclusion :

In this Bash Scripting Tutorial, we have learnt to override commands with the help of Example Bash Scripts.