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 8776757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:07:49+00:00 2026-06-13T19:07:49+00:00

Example of script usage ./foo.sh -v -r /home/ -s /home/user/file ./foo.sh -r /home/ -s

  • 0

Example of script usage

./foo.sh -v -r /home/ -s /home/user/file
./foo.sh -r /home/ -s /home/user/file

In parameter I always need a file or a folder to scan and a file for the database (-s database file)

inside foo.sh

function entrance()
{
while getopts "v:r:s" opt; do
  case $opt in
    v)
      echo "-v was triggered, Verbose mode" >&2
      ;;
    r)
      echo "-r was triggered, recursive mode: $OPTARG" >&2
      ;;
    s)
      echo "-s was triggered, DATABASE: $OPTARG" >&2
      ;;
    \?)
      echo "Invalid option: -$OPTARG" >&2
      exit 1
      ;;
    :)
      echo "Option -$OPTARG requires an argument." >&2
      exit 1
      ;;
  esac
done
}

I don’t know why it doesn’t work.

Please fix me.

Thanks

  • 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-13T19:07:50+00:00Added an answer on June 13, 2026 at 7:07 pm

    You probably forgot about $@ while calling the function. See this:

    #!/bin/bash
    
    function entrance() {
    while getopts "v:r:s" opt; do
      case $opt in
        v)
          echo "-v was triggered, Verbose mode" >&2
          ;;
        r)
          echo "-r was triggered, recursive mode: $OPTARG" >&2
          ;;
        s)
          echo "-s was triggered, DATABASE: $OPTARG" >&2
          ;;
        \?)
          echo "Invalid option: -$OPTARG" >&2
          exit 1
          ;;
        :)
          echo "Option -$OPTARG requires an argument." >&2
          exit 1
          ;;
      esac
    done
    }
    
    entrance "$@"
    

    And some explanation: Using getopts within user-defined-function in bourne shell

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

Sidebar

Related Questions

I have a shell script it's usage is: foo.sh <name> <type> <*.tar.gz> I want
Below is my example script: <li><a <?php if ($_GET['page']=='photos' && $_GET['view']!==projects||!==forsale) { echo (href=\#\
im looking for an example script. I saw one yesterday but for the life
I'm just beginning to learn python. I wrote an example script to test OOP
for example I have a script that needs to put it's parent directory on
I have that script: // ==UserScript== // @name example // @include http://xxx* // @require
Example taken from Mozilla's help page <script type="text/javascript"> re = /(\w+)\s(\w+)/; str = "John
Example: http://vincent-massaro.com/map/ Currently, the script allows you to click on a piece of the
Say for example you had a shell script that utilises inotifywait in the following
Code example: <script> var data = new Array(); data[0] = 'hi'; data[1] = 'bye';

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.