Bash - Passing Named Arguments to a Function

#!/bin/bash testNamedArgs () { for i in "$@" do case $i in -p=*|--prefix=*) PREFIX="${i#*=}" ;; -s=*|--searchpath=*) SEARCHPATH="${i#*=}" ;; -l=*|--lib=*) DIR="${i#*=}" ;; esac done echo "PREFIX: $PREFIX" echo "SEARCHPATH: $SEARCHPATH" echo "DIR: $DIR" } testNamedArgs foo bar baz -s="This is the S" --prefix="This is the prefix" --lib="This is the lib"

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.