Shell Script Tricky Question – Duplicate Functions

You can write functions in the shell script. And inside of them, you can write the logic for iterations (loops) or any other code. The tricky question is what happens when you give duplicate names in the script. It is applicable for both BASH and KSH (Korn shell).

Duplicate Functions

Script with Duplicate Function Names

The iterate() is a duplicate function. It ignores first function. it considers only last duplicate function.

Script with Duplicate Function Names
Script With Duplicate Functions

How it Works – see the full explanation

Here I have given two functions of iterate(). In the first iterate function, just I have given echo statement. Anyways, it will be skipped.

In the second iterate function, the variable arg1 holds first value of input supplied. The shift operator shifts the input values to left side.

The result after execution, display the shifted values. The supplied input for the function is ‘ a b c d e

Video – Result of the script

Related posts

Best Trainings

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.