Attempting to pass my array as a nested parameter to loop. A little lost.

I want to pass this array as a parameter.

IFS=$'\n'
fortune_lines=($(fortune |  fold -w 30 ))

Inside of this line

screen -p 0 -S ${SCREEN_SESSION} -X stuff "`printf "say ${fortune_lines[@]}\r"`"

And I am lost at this point.
I am thinking something like this?

Then make it loop..

 
for var in "${ArrayName[@]}"
do
  echo "${var}"
  # do something on $var
done

I just can seem to flesh it out. Any help or feedback would be great.

is this homework?

No. Its for my minecraft server. :cool:

pls post relevant info like execution logs, error msgs, (part) contents of variables, arrays, files...

Its a two part problem

So this .sh is the array that works fine (I think ) for what I need it to do.

#!/bin/bash 

IFS=$'\n' 
fortune_lines=($(fortune | fold -w 30))

for var in "${fortune_lines[@]}"
do
  echo "${var}"
done

but I want to append that array into a loop that would look like this (its not working - and I really have no idea what the next step should be to make this work ) but here is a rough idea

#!/bin/bash 

IFS=$'\n' 
fortune_lines=($(fortune | fold -w 30))
Screen_Session=$(mainscreen)
Screen_OneLiner=$(screen -p 0 -S ${Screen_Session} -X stuff "`printf "say ${fortune_lines[@]}\r"`")



for var in "${Screen_OneLiner[@]}"
do
  echo "${var}"
done


Then when executed I get a black window, in the bottom bar it says
"cannot exec stuff"

Then the terminal that I am

./

the .sh from prints and drops back to the prompt

 line 5: mainscreen: command not found
[screen is terminating]

Other info
I am starting my screen session (Screen version 4.00.03 (FAU) 23-Oct-06
) using

screen -S mainscreen

and the bash version I am using is
GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin12)

Take the parentheses away from $(mainscreen) - the parentheses are trying to execute a command called mainstream.

Mainscreen is not defined in the script.

Also looks like you need to

chmod +x stuff

. More info would probably get you more help.

... if stuff exists at all. Why don't you start with simple commands and constant parameters in your Screen_OneLiner? And, again, execution logs would help us help you.

What I think you want here is multiple say commands for each line of the fortune, try.

screen -p 0 -S ${Screen_Session} -X stuff "$(printf "say %s\r" ${fortune_lines[@]})"

Also (@zer0sig and @Rudic) stuff is a command line arg to screen that pushes text into the screen's input queue, it is not an external command.