---
title: "Shell Script Tricky Question – Duplicate Functions"
description: "Here is a tricky shell script question. What happens if you give duplicate function names in the script."
url: https://srinimf.com/2021/10/09/shell-script-tricky-question-duplicate-functions/
date: 2021-10-09
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2021/10/pexels-photo-7845470.jpeg?fit=1880%2C1253&ssl=1
categories: ["Shell scripts"]
tags: ["Duplicate function names"]
type: post
lang: en
---

# 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](https://srinimf.com/2017/04/09/what-happens-when-stop-run-given-in-subprogram/) you give duplicate names in the script. It is applicable for both BASH and KSH (Korn shell).

Related[How to Write a Script in K Shell](https://srinimf.com/2017/11/01/ksh-script-steps-to-create-awesome-way/)

*Duplicate Functions*

Related[How to Call a Shell Script from Another Script](https://srinimf.com/2021/11/01/heres-the-real-reason-to-include-script-in-other-script/)

## 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](https://i0.wp.com/srinimf.com/wp-content/uploads/2021/10/script.jpg?resize=723%2C417&ssl=1)*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

- [How to Change Default Shell In Ubuntu](https://srinimf.com/2021/10/18/heres-the-top-command-to-change-shells-in-ubuntu-quickly/)DateOctober 18, 2021
- [How to Write a Script in K Shell](https://srinimf.com/2017/11/01/ksh-script-steps-to-create-awesome-way/)DateNovember 1, 2017
- [Microland Interview: 2 Tricky Linux Shell Scripts](https://srinimf.com/2023/12/24/microland-interview-2-tricky-linux-shell-scripts/)DateDecember 24, 2023

Best Trainings

- Shell Script Tutorial – Bash Scripting for Linux/Unix/Bash
- Bash Scripting 1-Hour Crash Course: Write Scripts Today!

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2021%2F10%2F09%2Fshell-script-tricky-question-duplicate-functions%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2021%2F10%2Fpexels-photo-7845470.jpeg%3Ffit%3D1200%252C800%26ssl%3D1&description=Shell%20Script%20Tricky%20Question%20-%20Duplicate%20Functions)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2021/10/09/shell-script-tricky-question-duplicate-functions/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2021/10/09/shell-script-tricky-question-duplicate-functions/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2021/10/09/shell-script-tricky-question-duplicate-functions/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2021/10/09/shell-script-tricky-question-duplicate-functions/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20Shell%20Script%20Tricky%20Question%20-%20Duplicate%20Functions&body=https%3A%2F%2Fsrinimf.com%2F2021%2F10%2F09%2Fshell-script-tricky-question-duplicate-functions%2F&share=email)
-

### Like this:

Like Loading…
