Find the answer to your Linux question:
Results 1 to 3 of 3
Hi I'm trying to create an array with variable including hyphen but ksh refuses the first element (actually I replaced at by * since forum rules restricts URL embedded..) set ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2009
    Posts
    5

    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
    (actually I replaced at by * since forum rules restricts URL embedded..)


    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

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    how about this:
    Code:
    set +A allArgs
    allArgs[1]='-all'
    allArgs[2]='-date'
    allArgs[3]='test'

  3. #3
    Just Joined!
    Join Date
    Aug 2009
    Posts
    5
    10x

    here is another solution(in case you dont know what is the index for array)

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •