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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:44:56+00:00 2026-06-17T10:44:56+00:00

I know php programming but I am not familiar with bash script programming syntax.

  • 0

I know php programming but I am not familiar with bash script programming syntax.

I have this code snippet

EXPECTEDARGS=0
if [ $# -ne $EXPECTEDARGS -o "x$0" == "x"  -o $0 == "bash" ]; then
  echo "Usage:"
  echo "   Parameter 1: argument 1 missing"
  exit 1
fi

This correctly checks for at least 1 argument.

I want to understand what this code snippet means line by line. So far, I can only make out that EXPECTEDARGS is a variable.

After understanding the code snippet, I want to modify it to check for 2 arguments.

The code snippet will be in a github gist.

I aim to execute the script using

bash -c "$(curl -fsSL https://raw.github.com/gist/4491019)" <arg1> <arg2> 

without the <> symbols of course.

  • 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-17T10:44:57+00:00Added an answer on June 17, 2026 at 10:44 am
    • $# number of arguments.
    • $0 shell script name
    • $1,$2,…,$n argument 1, 2, etc
    • [ condition ] test one or more conditions, -ne not equal, -eq equal, -gt greater than, -lt lesser than, -o or, = compare string/number
    • “x$0” = x check if script name/prog name is empty

    if you want to know more, save the script as a file and try to print stuff with echo. Run the script with:

    bash -c ./script.sh
    

    or

    bash script.sh
    

    to mimic the behaviour of bash+curl

    [ ] or test is a good example, they are just a program, actually the same program, while checking $0 or argv[0] in C, they behave a little bit different.

    $ ls -l /bin/test /bin/\[
    -r-xr-xr-x  2 root  wheel  43120 Dec 11  2011 /bin/[*
    -r-xr-xr-x  2 root  wheel  43120 Dec 11  2011 /bin/test*
    

    If you run [ 2 -gt 1 ]; echo $? it will print 0 in your terminal, 0 means success everything else means failure. If you call test instead: test 2 -gt 1; echo $? it also print 0.

    so if just runs a program and checks the exit code, you can also do:

    if true; then
        echo success
    fi
    
    if false; then
        echo fail
    fi
    
    true; echo $?; false; echo $?
    

    will print: success, 0, 1

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

Sidebar

Related Questions

Pretty basic programming question, I know PHP have a function for it, but does
I know this question is probably straightfoward but I'm new to php and programming...
not sure why my code wont work, im teaching myself javascript i know php
I personally know limited PHP, however I have a script provided by another, that
This is sort of not relevant to programming but I think it also is:
i know the best approach when programming is not to disable errors,i have been
I do not know how many faces this problem. If I do programming in
I have to do a very simple operation but my programming skills are not
I know that it is not a programming question ? But i need a
i want to know whether simple_html_dom.php (http://simplehtmldom.sourceforge.net/manual.htm) uses cURL or not. I have a

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.