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.

Start Discussion

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.