[英]Bash Script : Handling Arguments
Can a bash/shell guru help me make a really simple bash script which handles the following - im struggling to get it working along these lines bash / shell专家可以帮助我制作一个非常简单的bash脚本来处理以下问题吗?
Input is as following 输入如下
./script #channel1,#channel2,#channel3 "This is the message"
or if easier.. 还是比较容易..
./script #channel1,#channel2,#channel3 -m This is the message
(anything after the -m is the message) (-m之后的任何内容都是消息)
Now I want to loop through each of the channels, and echo the message, ie 现在我想遍历每个通道,并回显消息,即
for channel in channels
echo channel $message
fi
thanks 谢谢
If you are writing it, it would be easier to do 如果您正在编写,这样做会更容易
usage ()
{
echo "usage: $0 <MESSAGE> <CHANNELS>"
exit
}
[[ $3 ]] || usage
message=$1
shift
for channel
do
echo $channel $message
done
channels=$1
message=$2
IFS=,
for channel in $channels
do echo $channel $message
done
Example: 例:
0>./script channel1,channel2,channel3 "This is the message"
channel1 This is the message
channel2 This is the message
channel3 This is the message
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.