[英]How do I declare a constant in shell script?
I can't find this information from the internet, is it not possible to declare a final constant variable whose value will not change after first initialization?我在网上找不到这个信息,是不是不能声明一个最终的常量变量,它的值在第一次初始化后不会改变?
I believe you can do something like:我相信您可以执行以下操作:
readonly DATA=/usr/home/data/file.dat
You can also do:你也可以这样做:
declare -r var=123
readonly FOO=bar
In bash
you can mark a variable read only by declaring it via the builtin readonly
like so:在
bash
,您可以通过内置readonly
声明变量来将变量标记为只读,如下所示:
readonly CONSTVAR=value
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.