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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Attempting to pass my array as a nested parameter to loop. A little lost.
# 1  
Old 10-30-2012
Bug Attempting to pass my array as a nested parameter to loop. A little lost.

I want to pass this array as a parameter.

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


Inside of this line

Code:
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..

Code:
 
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.

Last edited by briandanielz; 10-30-2012 at 03:13 AM.. Reason: Trying to make this make sense.
# 2  
Old 10-30-2012
is this homework?
# 3  
Old 10-30-2012
Quote:
Originally Posted by DukeNuke2
is this homework?
No. Its for my minecraft server. Smilie
# 4  
Old 10-30-2012
pls post relevant info like execution logs, error msgs, (part) contents of variables, arrays, files...
# 5  
Old 10-30-2012
Quote:
Originally Posted by RudiC
pls post relevant info like execution logs, error msgs, (part) contents of variables, arrays, files...
Quote:
Originally Posted by RudiC
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.

Code:
#!/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

Code:
#!/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
Code:
./

the .sh from prints and drops back to the prompt
Code:
 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
Code:
screen -S mainscreen

and the bash version I am using is
GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin12)
# 6  
Old 10-31-2012
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
Code:
chmod +x stuff

. More info would probably get you more help.
# 7  
Old 10-31-2012
... if stuffexists 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.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

The Shell lost the inverted comma in a nested ssh command

Hi, i want use this Comand for my psql request sh ssh -o StrictHostKeyChecking=no rootatemailaddress.de sudo psql -U postgres -c "select pg_terminate_backend(pid) from pg_stat_activity where datnam=\'$DB\';"'" but the shell lost the inverted comma for datnam=\'$DB\'. The request deliver... (2 Replies)
Discussion started by: peterpane007
2 Replies

2. Shell Programming and Scripting

How to pass function parameter to do loop?

Hi All, I have created one function for KSH and was running well with one parameter input since I just had to use $1 to get the parameter. Now I want to do loop for each parameter(actually filenames) . I have try to use do loop, but $i does not resolve to parameter instead it resolves to 1,... (5 Replies)
Discussion started by: mysocks
5 Replies

3. Shell Programming and Scripting

Pass array to a function and display the array

Hi All I have multiple arrays like below. set -A val1 1 2 4 5 set -A val2 a b c d . . . Now i would like to pass the individual arrays one by one to a function and display/ do some action. Note : I am using ksh Can you please advise any solution... Thanks in advance. (7 Replies)
Discussion started by: Girish19
7 Replies

4. Shell Programming and Scripting

awk loop using array:wish to store array values from loop for use outside loop

Here's my code: awk -F '' 'NR==FNR { if (/time/ && $5>10) A=$2" "$3":"$4":"($5-01) else if (/time/ && $5<01) A=$2" "$3":"$4-01":"(59-$5) else if (/time/ && $5<=10) A=$2" "$3":"$4":0"($5-01) else if (/close/) { B=0 n1=n2; ... (2 Replies)
Discussion started by: klane
2 Replies

5. Shell Programming and Scripting

Pass parameter

Hi, I have following for loop , please let me know how to get ${TXP_EXT_TABLE_${i}_SQL} parameter with 1DAY and 7DAY values. for i in 1DAY 7DAY do ${NZSQL_DIR}/nzsql -h ${HOST} -time -v ON_ERROR_STOP=1 -f ${SQL_DIR}/${TXP_EXT_TABLE_${i}_SQL} > ${TMP_LOG_FILE} 2>&1 done ... (4 Replies)
Discussion started by: sandy162
4 Replies

6. UNIX for Dummies Questions & Answers

How to pass the parameter value to a... ?

Hello I have a simple code like this one: #!/bin/ksh VER=$1 cat /usr/text | while read line do echo $line done Let's say $1=1.0.0 and the contents of text is: abcd.cfg asdf I would like the output to be like this abcd1.0.0.cfg asdf1.0.0 I am thinking of passing the... (5 Replies)
Discussion started by: khestoi
5 Replies

7. Shell Programming and Scripting

PHP: Search Multi-Dimensional(nested) array and export values of currenly worked on array.

Hi All, I'm writing a nagios check that will see if our ldap servers are in sync... I got the status data into a nested array, I would like to search key of each array and if "OK" is NOT present, echo other key=>values in the current array to a variable so...eg...let take the single array... (1 Reply)
Discussion started by: zeekblack
1 Replies

8. Shell Programming and Scripting

How to pass a parameter

Hi all, How to pass a parameter from a oracle pl/sql procedure parameter to shell environment and use it? (1 Reply)
Discussion started by: megh
1 Replies

9. UNIX for Dummies Questions & Answers

dsl connections lost when attempting to retrieve mail from my server.

suse linux 6.4 im running and i have port 110 for pop and smtp open, i have set up some email addresses for my friends, but they recieve errors saying that relaying is denied. i know this is to prevent spamming software from using my domain to send spam, but how do i let my users send their mail?... (6 Replies)
Discussion started by: norsk hedensk
6 Replies
Login or Register to Ask a Question