Bash脚本:处理参数
bash/shell大师能帮我制作一个非常简单的bash脚本来处理以下内容吗?我正努力让它按照这些思路工作 输入如下Bash脚本:处理参数,bash,shell,arguments,Bash,Shell,Arguments,bash/shell大师能帮我制作一个非常简单的bash脚本来处理以下内容吗?我正努力让它按照这些思路工作 输入如下 ./script #channel1,#channel2,#channel3 "This is the message" 或者更容易 ./script #channel1,#channel2,#channel3 -m This is the message 在-m之后的任何内容都是消息 现在我想通过每个通道循环,并回显信息,即 for channel in channel
./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
谢谢如果你正在写,那就更容易了 用法 { 回声使用率:$0 出口 } [$3]||用法 消息=$1 转移 频道 做 echo$channel$消息 完成 例如:
0>./script channel1,channel2,channel3 "This is the message"
channel1 This is the message
channel2 This is the message
channel3 This is the message
您好,谢谢您的反馈,但我无法让它工作。。。我键入的任何内容都会带来用法…?。/脚本这是一条消息channel1,channel2会带来“用法废话”…?@TylerEvans:不要在频道列表中包含逗号。回想一下$3表示第三个参数,在您的示例中,您只有两个参数,因为shell在带引号的字符串上分隔,然后是空格而不是逗号。祝大家好运。它不应该是[[$2]]| |用法吗?你的频道参数真的是以a开头的吗?如果是这样,那可能是问题的核心。告诉bash,从那里到行尾的所有内容都是注释。
0>./script channel1,channel2,channel3 "This is the message"
channel1 This is the message
channel2 This is the message
channel3 This is the message