Created
September 22, 2016 06:09
-
-
Save otgo/a3bdbb631146787701b2ea818bdc26f8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
declare -A ENTRY | |
VAR="HI EVERYBODY IM A SCRIPT BASH TO TEST PARAMETERS" | |
ENTRY[1]=$(/bin/bash -c 'echo "$1"' $VAR) | |
ENTRY[1-]=$(/bin/bash -c 'if [ $# -gt 0 ]; then echo "$@" ; fi' $VAR) | |
ENTRY[2]=$(/bin/bash -c 'echo "$2"' $VAR) | |
ENTRY[2-]=$(/bin/bash -c 'if [ $# -gt 1 ]; then echo "$(echo "$@" | cut -d " " -f2-)" ; fi' $VAR) | |
ENTRY[3]=$(/bin/bash -c 'echo "$3"' $VAR) | |
ENTRY[3-]=$(/bin/bash -c 'if [ $# -gt 2 ]; then echo "$(echo "$@" | cut -d " " -f3-)" ; fi' $VAR) | |
ENTRY[4]=$(/bin/bash -c 'echo "$4"' $VAR) | |
ENTRY[4-]=$(/bin/bash -c 'if [ $# -gt 3 ]; then echo "$(echo "$@" | cut -d " " -f4-)" ; fi' $VAR) | |
ENTRY[5]=$(/bin/bash -c 'echo "$5"' $VAR) | |
ENTRY[5-]=$(/bin/bash -c 'if [ $# -gt 4 ]; then echo "$(echo "$@" | cut -d " " -f5-)" ; fi' $VAR) | |
echo ${ENTRY[1-]} | |
<<comment | |
Only text in count, ex. VAR="1 2 3 4 5" | |
echo ${ENTRY[2]} | |
returns: 2 | |
VAR="1 2 3 4 5" | |
echo ${ENTRY[2-]} | |
returns: 2 3 4 5 | |
ENTRY[NUMBER] = Just one parameter. | |
ENTRY[NUMBER-] = Text from parameter. | |
comment | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment