Sending an array member to file

This may be a dupe, but the problem is not complex,it is simple issue.

I can create an array of string(s) located in positioning parameters for further processing. Works as expected.

Now I like to send / write each string , space separated words , into a file.

Of course I tried different ways , but so far no success.

So I need help, again.

Here is the snippet of scrip

for i in {2..32..2}; do
  104  MenuArray[$i]=$i$Space$menuCommand
  106  #append to file  
  107 echo "$LINENO array $MenuArray[$i]"  
  108 pause


HERE IS THE PROBLEM 

 append array member  to file
 

 109  echo "$MenuArray[$i]" >> "$PWD$DEBUG_DIR$DEBUG_MENU"


  110  echo "$LINENO  appeded to file "
  111  pause   
  112  ((i++))
  113     MenuArray[$i]=$menuDescription
  114      ((i++))
  115       done     
  116        echo "${MenuArray[@]}"
  117 :<<"cut"         


And here is an output - it "writes " an array member "index" to file

   	 	 	 	   + i=0
 + for i in {2..32..2}
 + MenuArray[$i]='2 CLI Command'
 + echo '107 array [2]'
 107 array [2]
 + pause


I do not know what you are doing and with the explanations given and the snipped of code mingled with residue line numbers and other wordings outside a pure syntactic code, it is not easy to comprehend.
Perhaps, in future posts you would suppress those and present only your strict code and what would you expect as output that it did not happen.

Consider:

echo "${MenuArray[$i]}" >> "$PWD$DEBUG_DIR$DEBUG_MENU"

Let me put it this way - I appreciate your code reply.

It does the job.

Please - In future limit your replies to facts.
I do not discuss "what I am doing" unless it has a bearing on the problem.

I do try to be as descriptive as I know and believe more info is better that less.
I do have an issue with inquisitive reply especially with comments on form / format.

I used to frequent a forum where "administrators wannabes"aways complained about "the code is not in code tags". In my view such attitude is naive and has a simple solution - if the post is "unreadable " etc. simply DO NOT REPLY.

To make sure _ I am NOT unloading on you , just letting you know how I feel.

Perhaps even after my sermon you would be kind enough to explain the syntax you used.

My "nano" text editor is not too trilled with it, but it works!

Hi, annacreek

I do not mean to offend you but I suggest you stop the sermons and place more pondering to what willing people is telling you.

I understand code but I do know what's in your head when you wrote what you posted and certainly the snippets you posted do not make it easy to understand nor does it help with the intention and desired output.

It would be helpful to always craft a desirable output and post it if the one you are getting is not right, specially if it is not obvious from the code. I do not think you can make that determination, so you can err in the side of cautions and communicate what that desired output should be.

It will help if you remove the line numbers from your script post and do not make manual edits that are not part of the correct syntax of the language you are using.

This is as far as my kindness goes.

3 Likes

You must enter the braces because the shell by default uses

${MenuArray}[$i]