bash 在bash脚本中的变量之间复制值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15094968/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Copy values between variables in bash script
提问by gomesg
How can I copy the numeric value in a variable to another variable in bash script. If this were C, I would do
如何将变量中的数值复制到 bash 脚本中的另一个变量。如果这是 C,我会这样做
int a=0;
int b;
a=b;
I am trying to do this:
我正在尝试这样做:
if [ $countip -gt $totalip ];
then
$countip -eq $srctip # <-- My problem is here!
echo $srctip
fi
回答by Warwick Masson
Just say
说啊
countip=$srctip
This is how assignment works in bash. This will set countip to the value of srctip. If you want to assign srctip then just write
这就是赋值在 bash 中的工作方式。这会将 countip 设置为 srctip 的值。如果你想分配 srctip 然后只写
srctip=$countip
Based on the comments below this looks like the one you want.
根据下面的评论,这看起来像你想要的。