0

I have a script like the following:

#!/bin/bash

declare -A aaa

while [ "$1" != "" ];
do
        case "$1" in
                -e|--env)
                        if [ ! "$2" == "" ] && [ ! "$3" == "" ]; then
                        aaa[$2]="$3"
                        fi
                        shift
                        shift
                        shift
                        ;;
                *)
                        echo "Error"
                        shift
                        ;;
        esac

done

for K in "${!aaa[@]}";
do
        str="$str --build-arg $K=\"${aaa[$K]}\""
done

#echo $str

./test_args.sh $str

It is called like:

./multi_args.sh -e arg1 "Hello Man!" -e arg2 Bye

in the second script test_args.sh, I get the built string str and print the arguments.

test_args.sh:

#!/bin/bash

while [ "$1" != "" ];
do
        echo "$1"
        shift
done

it supposed to printed like this:

arg1
Hello Man!
arg2
Bye

but it prints:

arg1
Hello 
Man!
arg2
Bye
A.H.
  • 63,967
  • 15
  • 92
  • 126
Super Hornet
  • 2,839
  • 5
  • 27
  • 55

0 Answers0