【问题标题】:Adding a string to the front of array loop?在数组循环的前面添加一个字符串?
【发布时间】:2012-10-21 16:53:15
【问题描述】:
#!/bin/bash
#OLDIFS=$IFS
IFS=$'\r'
    fortune_lines=($(fortune | fold -w 90))

    #Screen_Session=$"{mainscreen}"
        Screen_Session=`screen -ls|grep "\."|grep "("|awk '{print $1}'`
    Screen_OneLiner=$(screen -p 0 -S ${Screen_Session} -X stuff "`printf "${fortune_lines[@]}\r"`")
#IFS=$OLDIFS;
    for var in "${Screen_OneLiner[@]}"
      do
         echo    "${var}"
    done

好的,这个脚本有效(排序)。我需要将字符串“say”放在整个数组索引的前面。目前我只能让它在第一行打印出“say”。

【问题讨论】:

  • 是和否。是的,它是 osx 中“/usr/bin/say”中的内置命令。将文本变为说话。但我只需要使用 'say ' 作为字符串。 'say' 在我的用法中只是 java vm 中的命令。它是一个我的世界服务器,您需要在服务器的所有 cmets 前加上'say'
  • 显示当前输出和所需输出(我的 Cygwin 会话中没有这些命令)。
  • 我现在不在家,但基本上
  • 我现在不在家,但基本上,输出看起来像say line 0 of the array 然后是all the rest of the array loops without say on the front 所以我想说say on the front of each loop of the array

标签: arrays string bash loops append


【解决方案1】:

我们不需要像数组这样的玩意儿让事情变得复杂——我们可以让老旧的sed 来完成这项工作。

#!/bin/bash
fortune_lines=$(fortune | fold -w 90 | sed 's/^/say /')
Screen_Session=`screen -ls|grep "\."|grep "("|awk '{print $1}'`
screen -p 0 -S $Screen_Session -X stuff "$fortune_lines"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-06
    • 1970-01-01
    • 2015-12-03
    • 2011-01-08
    相关资源
    最近更新 更多