Created
August 4, 2011 18:53
-
-
Save rafaelrinaldi/1125931 to your computer and use it in GitHub Desktop.
Easy (maybe dumb also?) way to get short and long parameters of a Shell script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# author: Rafael Rinaldi (rafaelrinaldi.com) | |
# since: Aug 3, 2011 | |
# license: WTFPL | |
# A string with available options | |
options=$@ | |
# Options converted to an array | |
arguments=($options) | |
# Loop index | |
index=0 | |
# Variables I have | |
f="" | |
c="FFFFFF" | |
t="" | |
w="100%" | |
h="100%" | |
v="10.0.0" | |
sov="2.2" | |
for argument in $options | |
do | |
# Incrementing loop index | |
index=`expr $index + 1` | |
# Getting the parameters | |
case $argument in | |
-f|-file) f=${arguments[index]} ;; | |
-c|-color) c=${arguments[index]} ;; | |
-t|-title) t=${arguments[index]} ;; | |
-w|-width) w=${arguments[index]} ;; | |
-h|-height) h=${arguments[index]} ;; | |
-v|-version) v=${arguments[index]} ;; | |
-sov) sov=${arguments[index]} ;; | |
--help) echo "Script usage" ;; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment