Skip to main content
Home
Custom Software Development
  • Hosting
    • All Managed Appliances
    • Pricing
  • Products
    • All Products
    • SMT
    • Email Client & CRM
  • Consulting
    • All Consulting Services
    • Ruby on Rails
    • ReactJs
    • Drupal
    • Graphic Design
    • Pricing
Vote up!

1

Vote down!

How to parse command-line arguments in a bash script

Patterns in Programming
Issue 2024Q1 (current)
Patterns in Programming
while [ $# -gt 0 ]; do
  case "$1" in
    -p|--p_out=*)
      p_out="${1#*=}"
      ;;
    -a|--arg_1=*)
      arg_1="${1#*=}"
      ;;
    *)
      printf "***************************\n"
      printf "* Error: Invalid argument.*\n"
      printf "***************************\n"
      exit 1
  esac
  shift
done
Please log in to post comments:  
Login with Google

User account menu

  • Register
  • Log in

Pages

  • Issues
  • Tags
  • All Articles
  • Our Work
  • Careers
  • Contact us

Social Login

Authenticate through Google
Copyright (c) 2025 Wasya Co
Terms & Conditions

  201 W 5th St 11th Floor, Austin, TX 78701