shell中如何给外部函数的变量赋值??
-
- 帖子: 22
- 注册时间: 2012-03-09 18:08
shell中如何给外部函数的变量赋值??
函数如下,其名为csma.l,现要用shell编程调用此函数进行仿真,其中需要多次修改ftp_ptk_size,diameter,average三个参数(已用红颜色表示),然后将所得数据记录下来,现不知道如何在shell中给这三个变量赋值,以自动完成仿真。望各位高手帮助!!!PS:函数功能大家不用细看,告诉我如何赋值就行。
新手,问题没什么技术含量,还望谅解!先在此谢过各位!
# This is a sample input file for the simulator
# it can also be found as lang/example.l
# To see if your simulator is OK, run it on this example as
# simulate example.l
# Remember that your REALDIR environment variable should be set
# to something reasonable
# the header section is optional
header
{
network: example;
version: 0;
}
# nest_params section is optional. Default passtime is 1 second
# default maxnodes is MAXNODES in config.h and default monitor is
# custom_monitor in kernel/monitor.c
nest_params {
passtime = 1,0;
maxnodes = 30;
monitor = custom_monitor;
}
# real_params section is also optional. Default definitions are in
# lang/lang.yacc
real_params {
inter_pkt_delay = 5.0;
# seconds (optional - not used)
random_seed = 0;
buffer_size = 440000;
# bytes (different from REAL3.0)
ftp_pkt_size = 500;
# bytes
telnet_pkt_size = 40;
# bytes
ack_size = 40;
# bytes
ftp_window = 600;
# packets
telnet_window = 400;
# packets
decongestion_mechanism = 1;
# 1 = drop from tail
# 2 = drop from head
# 3 = drop from random position
real_number = 0;
# used for distributed REAL
router_node = 0;
# used for distributed REAL
util_time = 1.0;
# time interval over which to
# measure router utilization (secs)
diameter = 0.1;
# diameter of LAN segment (secs)
end_simulation = 10;
# simulation end time in seconds
print_interval = 1;
# print and flush statistics every
# print_interval seconds
scale_factor = 1;
# time scale factor; if scale factor =
# 1000, 1 simulated second = 1ms realtime
}
nodes{
# first define the default node type
# all fields are optional
default{
function = ecn_slave;
dest = 1;
# destination node to send to
start_time = 0,10000;
# start node at seconds, microseconds
plot = true ;
# set to true if you want to plot data
num_pkts = 1000000000;
# number of packets to send
average = 20000.0;
# declared average rate in bits/sec
}
# for each source, just need to specify
# what is different compared to the default
node 1 { function = ecn_master;}
node 2 { function = ecn_slave;}
node 3 { function = ecn_slave;}
node 4 { function = ecn_slave;}
node 5 { function = ecn_slave;}
node 6 { function = ecn_slave;}
}
edges{
default {
bandwidth = 2000000;
# in bits/sec
latency = 0;
# in microseconds
}
{ 1 -> 2;}
{ 1 -> 3;}
{ 1 -> 4;}
{ 1 -> 5;}
{ 1 -> 6;}
}
新手,问题没什么技术含量,还望谅解!先在此谢过各位!
# This is a sample input file for the simulator
# it can also be found as lang/example.l
# To see if your simulator is OK, run it on this example as
# simulate example.l
# Remember that your REALDIR environment variable should be set
# to something reasonable
# the header section is optional
header
{
network: example;
version: 0;
}
# nest_params section is optional. Default passtime is 1 second
# default maxnodes is MAXNODES in config.h and default monitor is
# custom_monitor in kernel/monitor.c
nest_params {
passtime = 1,0;
maxnodes = 30;
monitor = custom_monitor;
}
# real_params section is also optional. Default definitions are in
# lang/lang.yacc
real_params {
inter_pkt_delay = 5.0;
# seconds (optional - not used)
random_seed = 0;
buffer_size = 440000;
# bytes (different from REAL3.0)
ftp_pkt_size = 500;
# bytes
telnet_pkt_size = 40;
# bytes
ack_size = 40;
# bytes
ftp_window = 600;
# packets
telnet_window = 400;
# packets
decongestion_mechanism = 1;
# 1 = drop from tail
# 2 = drop from head
# 3 = drop from random position
real_number = 0;
# used for distributed REAL
router_node = 0;
# used for distributed REAL
util_time = 1.0;
# time interval over which to
# measure router utilization (secs)
diameter = 0.1;
# diameter of LAN segment (secs)
end_simulation = 10;
# simulation end time in seconds
print_interval = 1;
# print and flush statistics every
# print_interval seconds
scale_factor = 1;
# time scale factor; if scale factor =
# 1000, 1 simulated second = 1ms realtime
}
nodes{
# first define the default node type
# all fields are optional
default{
function = ecn_slave;
dest = 1;
# destination node to send to
start_time = 0,10000;
# start node at seconds, microseconds
plot = true ;
# set to true if you want to plot data
num_pkts = 1000000000;
# number of packets to send
average = 20000.0;
# declared average rate in bits/sec
}
# for each source, just need to specify
# what is different compared to the default
node 1 { function = ecn_master;}
node 2 { function = ecn_slave;}
node 3 { function = ecn_slave;}
node 4 { function = ecn_slave;}
node 5 { function = ecn_slave;}
node 6 { function = ecn_slave;}
}
edges{
default {
bandwidth = 2000000;
# in bits/sec
latency = 0;
# in microseconds
}
{ 1 -> 2;}
{ 1 -> 3;}
{ 1 -> 4;}
{ 1 -> 5;}
{ 1 -> 6;}
}
- lilydjwg
- 论坛版主
- 帖子: 4258
- 注册时间: 2009-04-11 23:46
- 系统: Arch Linux
- 联系:
Re: shell中如何给外部函数的变量赋值??
这只是文本文件的修改,不用说得那么高深。使用 sed 就行。
- Fermat618
- 帖子: 728
- 注册时间: 2008-12-28 16:01
- 枫叶饭团
- 帖子: 14683
- 注册时间: 2010-06-16 1:05
- 系统: Mac OS X
- 来自: Tencent
- 联系:
Re: shell中如何给外部函数的变量赋值??
重定向可以把数值记录进文本,修改变量正如ls所说,只是更改文本内的数值,sed就行了6
-
- 帖子: 22
- 注册时间: 2012-03-09 18:08
Re: shell中如何给外部函数的变量赋值??
只有这个方法么?这个还是略微有点复杂,我要改5次ftp_ptk_size和diameter,每次修改之后又要修改10次average,改完后执行20次,字符串替换的话就每次替换都要写一行代码,并且顺序还不能乱,很纠结啊!!!lilydjwg 写了:这只是文本文件的修改,不用说得那么高深。使用 sed 就行。
- lilydjwg
- 论坛版主
- 帖子: 4258
- 注册时间: 2009-04-11 23:46
- 系统: Arch Linux
- 联系:
Re: shell中如何给外部函数的变量赋值??
问出这种问题只能说明你不会 shell 或者编程。你等授人以鱼的人来吧。ahgcookie 写了:只有这个方法么?这个还是略微有点复杂,我要改5次ftp_ptk_size和diameter,每次修改之后又要修改10次average,改完后执行20次,字符串替换的话就每次替换都要写一行代码,并且顺序还不能乱,很纠结啊!!!lilydjwg 写了:这只是文本文件的修改,不用说得那么高深。使用 sed 就行。
-
- 帖子: 992
- 注册时间: 2007-12-05 10:57
- 系统: ubuntu14.04
- 来自: 金山
Re: shell中如何给外部函数的变量赋值??
ahgcookie 写了:只有这个方法么?这个还是略微有点复杂,我要改5次ftp_ptk_size和diameter,每次修改之后又要修改10次average,改完后执行20次,字符串替换的话就每次替换都要写一行代码,并且顺序还不能乱,很纠结啊!!!lilydjwg 写了:这只是文本文件的修改,不用说得那么高深。使用 sed 就行。
改5次ftp_ptk_size和diameter,每次修改之后又要修改10次average,改完后执行20次
如果你要做红色字n次,你只要做一次 ,shell才有可能帮你做剩下的n-1次。
但这一次必须你手工做
看楼主的意思也许这样会好些:
开2 个终端 ,一个改ftp_ptk_size和diameter,另一个单独改average。
-
- 帖子: 22
- 注册时间: 2012-03-09 18:08
Re: shell中如何给外部函数的变量赋值??
新手啊,学shell也就几个小时,望谅解!lilydjwg 写了:问出这种问题只能说明你不会 shell 或者编程。你等授人以鱼的人来吧。ahgcookie 写了:只有这个方法么?这个还是略微有点复杂,我要改5次ftp_ptk_size和diameter,每次修改之后又要修改10次average,改完后执行20次,字符串替换的话就每次替换都要写一行代码,并且顺序还不能乱,很纠结啊!!!lilydjwg 写了:这只是文本文件的修改,不用说得那么高深。使用 sed 就行。
- lilydjwg
- 论坛版主
- 帖子: 4258
- 注册时间: 2009-04-11 23:46
- 系统: Arch Linux
- 联系:
Re: shell中如何给外部函数的变量赋值??
没什么谅解不谅解的,我懒得写新手教程而已。不过社区通常倾向于不直接帮提问者写代码的。嗯,你付费的话我可以考虑ahgcookie 写了: 新手啊,学shell也就几个小时,望谅解!

-
- 帖子: 1453
- 注册时间: 2008-05-24 8:30
Re: shell中如何给外部函数的变量赋值??
类似这样:
修改其它两个变量的,照葫芦画瓢就行了。
代码: 全选
for ftp_ptk_size in 500 600 800 1000 1500; do
sed "/ftp_ptk_size/s/=.*/= $ftp_ptk_size" csma.l > csma_fps_$ftp_ptk_size.l;
do_simulation csma_fps_$ftp_ptk_size.l # 这里指的是执行你的仿真,别照抄!
done
-
- 帖子: 919
- 注册时间: 2009-07-01 22:04
- lilydjwg
- 论坛版主
- 帖子: 4258
- 注册时间: 2009-04-11 23:46
- 系统: Arch Linux
- 联系:
Re: shell中如何给外部函数的变量赋值??
他的表述朋问题。fnan 写了:既然是函数,难道不能直接用 $1 $2 $3 传参数?