1

bash/shell 大师能否帮助我制作一个非常简单的 bash 脚本来处理以下内容 - 我正在努力让它按照这些思路工作

输入如下

./script #channel1,#channel2,#channel3 "This is the message"  

或者如果更容易..

./script #channel1,#channel2,#channel3 -m This is the message

(-m 之后的任何内容都是消息)

现在我想遍历每个通道,并回显消息,即

for channel in channels
    echo channel $message
fi

谢谢

4

2 回答 2

0

如果你正在写它,它会更容易做

usage ()
{
  echo "usage: $0 <MESSAGE> <CHANNELS>"
  exit
}

[[ $3 ]] || usage
message=$1
shift

for channel
do
  echo $channel $message
done
于 2013-04-26T01:47:32.107 回答
0
channels=$1
message=$2
IFS=,
for channel in $channels
do  echo $channel $message
done

例子:

0>./script channel1,channel2,channel3 "This is the message"
channel1 This is the message
channel2 This is the message
channel3 This is the message
于 2013-11-05T10:33:05.433 回答