Bash array as argument inside of screen

故事扮演 提交于 2020-01-24 14:07:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!