1

ns-3模拟器文档中,它们提供了一个简单的 bash 函数来简化您的生活:

function waff {
   CWD="$PWD"
   cd $NS3DIR
   ./waf --cwd="$CWD" $*
   cd -
}

该函数应该执行位于 ns-3 根文件夹中但在您实际所在的文件夹中的./waf程序。

因此,在~/project$ waff --run firstwaf 的情况下,将运行~/project文件夹中的第一个脚本。

但是,如果我尝试通过向脚本命令添加一个参数来运行任何模拟,就像~/project$ waff --run "first --PrintHelp"它会引发错误一样

waf: error: no such option: --PrintHelp.

它仅在我实际从根文件夹运行脚本而没有waff功能时才有效。

如何修改函数以使其将 $* 扩展为双逗号之间的参数?

4

2 回答 2

2

好吧,我感到很尴尬,因为解决方案比预期的要容易得多。

如果任何使用 DCE 的人有同样的问题,这就像引用 $* 一样简单:

./waf --cwd="$CWD" $*

和:

./waf --cwd="$CWD" "$*"
于 2015-02-17T18:43:43.887 回答
0

这个函数适用于我的 bash(假设你定义了环境变量 $NS3DIR):

function waff {
CWD="$PWD"
cd $NS3DIR >/dev/null
./waf --cwd="$CWD" "$@"
cd - >/dev/null
}

它有效的证明是:

$ waff --run "wifi-simple-adhoc --help"
Waf: Entering directory `/home'
Waf: Leaving directory `/home'
'build' finished successfully (2.013s)
ns3.22-wifi-simple-adhoc-debug [Program Arguments] [General Arguments]

Program Arguments:
    --phyMode:     Wifi Phy mode [DsssRate1Mbps]
    --rss:         received signal strength [-80]
    --packetSize:  size of application packet sent [1000]
    --numPackets:  number of packets generated [1]
    --interval:    interval (seconds) between packets [1]
    --verbose:     turn on all WifiNetDevice log components [false]

General Arguments:
    --PrintGlobals:              Print the list of globals.
    --PrintGroups:               Print the list of groups.
    --PrintGroup=[group]:        Print all TypeIds of group.
    --PrintTypeIds:              Print all TypeIds.
    --PrintAttributes=[typeid]:  Print all attributes of typeid.
    --PrintHelp:                 Print this help message.

$ waff --run wifi-simple-adhoc --command-template=" %s --help"
Waf: Entering directory `/home'
Waf: Leaving directory `/home'
'build' finished successfully (1.816s)
ns3.22-wifi-simple-adhoc-debug [Program Arguments] [General Arguments]

Program Arguments:
    --phyMode:     Wifi Phy mode [DsssRate1Mbps]
    --rss:         received signal strength [-80]
    --packetSize:  size of application packet sent [1000]
    --numPackets:  number of packets generated [1]
    --interval:    interval (seconds) between packets [1]
    --verbose:     turn on all WifiNetDevice log components [false]

General Arguments:
    --PrintGlobals:              Print the list of globals.
    --PrintGroups:               Print the list of groups.
    --PrintGroup=[group]:        Print all TypeIds of group.
    --PrintTypeIds:              Print all TypeIds.
    --PrintAttributes=[typeid]:  Print all attributes of typeid.
    --PrintHelp:                 Print this help message.
于 2015-05-06T13:14:47.407 回答