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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:53:26+00:00 2026-05-18T01:53:26+00:00

I have a executable shell script name project2. Following is one of the instruction

  • 0

I have a executable shell script name project2. Following is one of the instruction my teacher gave me on the project.

This script must accept at least one
command line parameter: the directory
where its output is to be placed. If
that directory is not given on the
command line, the script should use a
reasonable default directory.

Can you please tell me how can I make my script accept a command line. I haven’t done anything like that before. Any help would be greatly appreciated. Thanks a lot.

  • 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-05-18T01:53:27+00:00Added an answer on May 18, 2026 at 1:53 am

    For bash, command line parameters are stored in $1, $2, and so on, while $# will give you the count. In addition, shift can be used to shift them all “left” by one position and drop the count.

    The following script is a good starting point for understanding how the parameters work:

    echo $#
    while [[ $# -gt 0 ]] ; do
        echo "$1"
        shift
    done
    

    When you run it with:

    ./myprog.sh hello there my name is "pax     diablo"

    the output is:

    6
    hello
    there
    my
    name
    is
    pax     diablo
    

    The basic idea of your assignment is:

    • check the parameter count to see if it’s zero.
    • if it is zero, set a variable to some useful default.
    • if it isn’t zero, set that variable based on the first parameter.
    • do whatever you have to do with that variable.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an executable which is part of a batch process. This one executable
I have this shell script #!/bin/sh ############################################################# # Example startup script for the SecureTrading
I have a project that generates a shell script at CMake time (with file(WRITE
Assume I have an executable called 'exe' which spawns a child process. This child
I have the problem running executable .jar file. I've created a project which contains
I have a perl script (or any executable) E which will take a file
I have created a tcsh shell script as follows: #!/bin/tcsh setenv PATH setenv PATH
I have a script, that I need to run after committing to a project
I have a Python script script.py that has been defined as executable and which
I have built an executable shell that using MEF loads assemblies (MEF Parts) and

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.