Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9126197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:59:00+00:00 2026-06-17T06:59:00+00:00

Here is my shell script and the error I get when running it: #!/bin/bash

  • 0

Here is my shell script and the error I get when running it:

#!/bin/bash

path=$1
execute=$2
a=$3
operation=$4
name=$5

if [ "$operation" == "run" ]; then
    cd $path
   ./$execute $a 
fi
elif [ "$operation" == "copy" ]; then
    mkdir -p $path
    cp $execute $path/$name 
fi
elif [ "$operation" == "delete" ]; then
     rm $path
     cd copy
     rm $name
     cd ..
     rmdir copy
fi
./commandsScript.sh: line 14: syntax error near unexpected token `elif'
./commandsScript.sh: line 14: `elif [ "$operation" == "copy" ]; then'

I’ve spent a long time trying all sort if-else statements variances but have not found the error solution. May someone help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:59:01+00:00Added an answer on June 17, 2026 at 6:59 am

    Consider using a case expression instead of a set of chained if statements:

    case "$operation" in
    run)
        cd "$path"
        ./"$execute" "$a"
        ;; 
    copy)
        mkdir -p "$path"
        cp "$execute" "$path/$name"
        ;;
    delete)
        rm "$path"
        cd copy
        rm "$name"
        cd ..
        rmdir copy
        ;;
    esac
    

    I’ve also taken the liberty to quote all of your parameter expansions, which is what you should get into the habit of doing to make your script robust against arguments/variables with embedded whitespace.

    Also, I would advise investing in proper error handling.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's a simple defun to run a shell script: (defun bk-konsoles () Calls: bk-konsoles.bash
Here is my try : #!/Usr/bin/emacs --script (let ((default-directory /home/vision)) (shell-command git pull;) but
Following the advice here I can get a shell script in JavaScript that runs
If I use a here document in a shell script that contains multiple backslashes
Here's what I'm trying to achieve: open a shell (korn or bash, doesn't matter),
I have the following script #!/bin/sh if [cat stream_should_be_running.txt == 'true']; then #file will
I have been trying to run Linux shell script on Windows machine. to run
I have a custom shell script to make twitter bootstrap from source and then
I am facing a problem in a bash shell script. This script is supposed
I am trying to run a shell script from within a .vimrc file (three

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.