且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

bash脚本问题

更新时间:2023-12-05 19:52:16

那么,使用grep命令查找的HWaddr第一,所以在这此行的第五个领域是有问题的网卡的MAC地址 - 而不是你的本地IP地址。

Well, you grep for HWaddr first, so the fifth field on this this line is the MAC address of the network adapter in question - not your local IP address.

其他建议的解决方案是简单呼应的结果,这意味着如果为eth0在本例中是不是可以在该行被执行的时间点,它不会工作。

Others have suggested the solution is to simply echo the result, meaning if eth0 in this example is not available at that point in time which the line gets executed, it will not work.

据我了解,你想,而不是把所需的命令行中的变量,然后评估的后面。这种模式通常被称为懒惰的评价,然后在bash是由可能通过使用的评估内置的:

From what I understand you wish instead to put the desired command line in a variable, then evaluate it later on. This pattern is commonly called lazy evaluation, and is made possible in bash by using the eval builtin:

#put the desired command in variable
CASS_INTERNAL='ifconfig eth0 | grep HWaddr | awk "{print \$5}"'

# ....

#at later on - evaluate its contents!
eval $CASS_INTERNAL
11:22:33:aa:bb:cc