【问题标题】:array allowed not allowed数组 允许 不允许
【发布时间】:2016-09-22 11:14:31
【问题描述】:

我有脚本“proc 备份”。我必须给每个目录很多字来允许或不允许。 我认为与数组集成。但我没有领先...

或者有什么更简单的吗?

bind pubm - "*fertig*" backup

proc backup {nick host handle channel text} {
    set name[lindex [split [stripcodes bcru $text]] 2]
    set dir[lindex [split [stripcodes bcru $text]] 4]

    if {[catch {exec sh backup.sh $dir $name} error]} {
        putlog $error
    }

    putnow "PRIVMSG $channel :backup $name done";
}

array set allowed { 
    "dir1"          "to rar"
    "dir2"          "backupserver1 "
    "dir3"          "2016 2017"
}

array set not_allowed { 
    "dir1"          "test crap"
    "dir2"          "old backupserver2 jpg zip"
    "dir3"          "2015 2014 2013 2012 2011 2010 209 19"
}

编辑:

来自 irc 的行:( lindex 2 和 4)

仅当名称中的该单词为时才运行 backup.sh

word0 word1 backupserver1 word3 dir2

当另一个单词时不运行备份

word0 word1 backupserver55 word3 dir2

不运行 backup.sh

word0 word1 测试 word3 dir1 word0 word1 废话 word3 dir1

仅当名称中的该单词为时才运行 backup.sh

word0 word1 黑色 word3 dir1

仅当 $name 中允许的集合中的单词是时运行。 当 $name 中的 not_allowed 中有一个单词时不运行。

【问题讨论】:

  • 请多写一些关于您预期会发生什么和不会发生什么的信息。现在,我不明白allowednot_allowed 数组的真正意义是什么。
  • 示例:当在 dir1 ($dir) 中的文本包括 ($name) “to” 或 “rar”(允许从数组集)然后 make if {[catch {exec sh backup.sh . ...,当在 dir1 ($dir) 中的文本包括 ($name) "test" 或 "crap" (来自数组集 not_allowed) 然后停止 (retourn 0),我希望它更好。问候

标签: arrays tcl


【解决方案1】:

以下 2 行在变量名和值之间缺少一个空格。

set name[lindex [split [stripcodes bcru $text]] 2]
set dir[lindex [split [stripcodes bcru $text]] 4]

试试这个:

set name [lindex [split [stripcodes bcru $text]] 2]
set dir [lindex [split [stripcodes bcru $text]] 4]

【讨论】:

  • 是的,谢谢,它从副本中删除了..但这不是问题:)
【解决方案2】:

我现在已经做了这个来测试,当我有一个单词然后工作完美时,

"dir1"          "rar"

当有2个字时

"dir1"          "rar to"

不工作。

如果单词是“rar”或来自$relname 的文本中的单词“to”,我想回复是

bind pubm - "*fertig*" trade

proc backup {nick host handle channel text} {

set name [lindex [split [stripcodes bcru $text]] 2]
set dir [lindex [split [stripcodes bcru $text]] 4]

set rulesall [rulesallow $dir $release]

putnow "PRIVMSG $channel :rulesall $rulesall"
}


array set allowed { 
"dir1"          "rar"

}


proc rulesallow { cat relname} {
global allowed  
foreach {category allowede} [array get allowed] {
    if { [string match -nocase "*$allowede*" "$relname"] } {
    return $allowede;
    } else {

    }
}
}

测试是否删除了 sh 命令。

问候

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-23
    • 2014-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-09
    相关资源
    最近更新 更多