Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
################################################################################ # Function: parse_cmdline # Description: Parses the command-line using the enhanced version of getopt # Arguments: $@ :- Command-line arguments (required) # Requires: Global variables $USER_NAME, $DEST_DIR, $IS_REMOVE, and # $IS_VERBOSE # Outputs: Sets above-mentioned global variables based on given # command-line arguments function parse_cmd_line { # Ensure that the enhanced version of getopt is available ! getopt --test > /dev/null if (( "${PIPESTATUS[0]}" != 4 )); then echo "I'm sorry, the enhanced version of getopt is required. Exiting." >&2 exit 1 fi # Initialize the global variables USER_NAME='' DEST_DIR='' IS_VERBOSE='' IS_REMOVE='' # Parse the command-line options if ! readonly PARSED_OPTIONS=$(getopt --options=${OPTIONS} \ --longoptions=${LONGOPTS} \ --name "$(basename "$0")" -- "$@"); then echo 'Unknown error parsing getopt options. Exiting.' >&2 exit 2 fi eval set -- "${PARSED_OPTIONS}" # Extract and validate command-line options and their arguments, if any while (( $# >= 1 )); do case "$1" in -u|--user) USER_NAME=$(trim "$2") ; shift 2 ;; -d|--destdir) DEST_DIR=$(chomp_slash "$(trim "$2")") ; shift 2 ;; -r|--remove) IS_REMOVE='true' ; shift ;; -v|--verbose) IS_VERBOSE='true' ; shift ;; -h|--help) usage_exit 0 ;; --) shift ; break ;; *) usage_exit 3 >&2 ;; esac done # Ensure that required options have been supplied if [[ -z "${USER_NAME}" || -z "${DEST_DIR}" ]]; then usage_exit 4 >&2 fi } # parse_cmd_line
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)