Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

getopts without argument

#!/bin/bash

while getopts ":a:b:cd" options; do 
# Option -a -b need arguments / -c -d doesn't need argument to work
    case "${options}" in
  		a)
          VARA=${OPTARG}
        ;;
		b)
          VARB=${OPTARG}
        ;;
		c)
          echo "Option -c"
        ;;
		d)
          echo "Option -d"
        ;;
        :)                         # If expected argument omitted:
     	  echo "Error: -${OPTARG} requires an argument."
          exit 1                       
        ;;
        *)                         # If unknown (any other) option:
          echo "Error: unknown option"
          exit 1
        ;;
	esac
done
Comment

PREVIOUS NEXT
Code Example
Shell :: ansible copy 
Shell :: pip install without dependencies 
Shell :: loop over array of strings bash 
Shell :: cli zip 
Shell :: dotenv installation 
Shell :: install csv 
Shell :: bash read file into variable 
Shell :: apt install xfce 
Shell :: git set upstream remote branch 
Shell :: install golang 
Shell :: manjaro nvidia driver 
Shell :: zsh: command not found: npm 
Shell :: sudo a terminal is required to read the password 
Shell :: .gitignore not working 
Shell :: nvcc not found in jetson nano 
Shell :: git submodule remove 
Shell :: pull or fetch changes 
Shell :: how to both add and commit in git 
Shell :: ngrok install authtoken 
Shell :: sudo systemctl restart networking 
Shell :: bash float operation 
Shell :: depmod: not found 
Shell :: yarn check package version 
Shell :: search file in ubuntu 
Shell :: remove eclipse from ubuntu 
Shell :: install discord fedora 
Shell :: gitignore all log files 
Shell :: git change user of last commit 
Shell :: linux size of folder and subfolders 
Shell :: split command in splunk 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =