Problem to initialize ksh array when first element includes hyphen

Hi

I'm trying to create an array with variable including hyphen

but ksh refuses the first element

set -A allArgs
set +A allArgs ${allArgs[@]} -all
set +A allArgs ${allArgs[@]} -date
set +A allArgs ${allArgs[@]} test

./test.ksh[11]: -all: bad option(s)

It happens only when first element is like this:

set +A allArgs ${allArgs[@]} all
set +A allArgs ${allArgs[@]} -date
set +A allArgs ${allArgs[@]} test

print "Array is: ${allArgs[@]}"

Array is: all -date test

Because "allArgs" is empty.first time, it's treating "-all" as an argument to "set".

If you have some values in allArgs before appending itself then -add, the problem goes away.

This is exactly the problem

I do want the first element to be with hyphen since all script arguments including hyphen.

What is the way to do it ?

Oh, I see! Might have helped if I read the subject line :slight_smile:

$ set -A allArgs -- -all
$ echo ${allArgs[@]}
-all

$ set -A allArgs -- ${allArgs[@]} -date
$ echo ${allArgs[@]}
-all -date

many thanks

this is exactly what I was looking for...