问题
The below code is is not working as I expect it to. I might be because I am doing this all wrong but I think it may be a quoting issue.
#!/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
I think I am not quoting something correctly because when I attempt to execute this. I get..
line 5: mainscreen: command not found
[screen is terminating
Essentially I am attempting to add this function (that works)
IFS=$'\n'
fortune_lines=($(fortune | fold -w 30))
To this screen one liner
screen -p 0 -S ${Screen_Session} -X stuff "`printf "say ${fortune_lines[@]}\r"`"
Then have it loop the array
for var in "${ArrayName[@]}"
do
echo "${var}"
done
So I am not sure how far I am away (in code) to what I am trying to do. Any help would be great.
回答1:
Since feature requests to mark a comment as an answer remain declined, I copy the above solution here.
I managed to get this to work... gist.github.com/4006586 – user1787331
回答2:
This line is problematic
Screen_Session=$(mainscreen)
You are using command substitution here, so if mainscreen
is not a valid command, you'll get command not found
error.
Maybe you mean to use braces instead of parentheses?
来源:https://stackoverflow.com/questions/13150735/bash-array-as-argument-inside-of-screen