SHELLDECLARE的简单介绍
AB资源网 2023-04-24 08:47 78 浏览 0 评论
本文目录一览:
- 1、shell脚本某条语句中为什么要declare
- 2、linux shell 关联数组的一个小问题
- 3、Linux shell脚本编程——本地语言设置为中文
- 4、shell脚本中,无法获取“关联数组”(字典)的key,尝试过很多方法,输出都不对,求教
shell脚本某条语句中为什么要declare
declare用来定义后面的变量,比如变量A,变量B,变量sum_xx,如果没有declare,A B sum_xx就会当成一条命令语句,当然会找不到。
linux shell 关联数组的一个小问题
shell 并不支持关联数组。
只有awk才支持关联数组。
shell只支持index数字类型的数组,凡是不是数字的,都会当做0,或者-1,也就是最后的那个元素。
详细参见bash的man手册。
Arrays
Bash provides one-dimensional array variables. Any variable may be used as an array; the declare builtin
will explicitly declare an array. There is no maximum limit on the size of an array, nor any requirement
that members be indexed or asSigned contiguously. Arrays are indexed using integers and are zero-based.
An array is created Automatically if any variable is asSigned to using the syntax name[subscript]=value.
The subscript is treated as an arithmetic expression that must evaluate to a number greater than or equal
to zero. To explicitly declare an array, use declare -a name (see SHELL BUILTIN COMMANDS below).
declare -a name[subscript] is also accepted; the subscript is ignored. Attributes may be specified for
an array variable using the declare and readonly builtins. Each attribute applies to all members of an
array.
Arrays are asSigned to using compound assignments of the form name=(value1 ... valuen), where each value
is of the form [subscript]=string. Only string is required. If the optional brackets and subscript are
supplied, that index is asSigned to; otherwise the index of the element asSigned is the last index
asSigned to by the statement plus one. Indexing starts at zero. This syntax is also accepted by the
declare builtin. Individual array elements may be asSigned to using the name[subscript]=value syntax
introduced above.
Any element of an array may be referenced using ${name[subscript]}. The braces are required to avoid
conflicts with pathname expansion. If subscript is @ or *, the word expands to all members of name.
These subscripts differ only when the word appears within double quotes. If the word is double-quoted,
${name[*]} expands to a single word with the value of each array member separated by the first character
of the IFS special variable, and ${name[@]} expands each element of name to a separate word. When there
are no array members, ${name[@]} expands to nothing. If the double-quoted expansion occurs within a
word, the expansion of the first parameter is joined with the beginning part of the original word, and
the expansion of the last parameter is joined with the last part of the original word. This is analogous
to the expansion of the special parameters * and @ (see Special parameters above). ${#name[subscript]}
expands to the length of ${name[subscript]}. If subscript is * or @, the expansion is the number of ele-
ments in the array. Referencing an array variable without a subscript is equivalent to referencing ele-
ment zero.
The unset builtin is used to destroy arrays. unset name[subscript] destroys the array element at index
subscript. Care must be taken to avoid unwanted side effects caused by filename generation. unset name,
where name is an array, or unset name[subscript], where subscript is * or @, removes the entire array.
The declare, local, and readonly builtins each accept a -a option to specify an array. The read builtin
accepts a -a option to assign a list of words read from the standard input to an array. The set and
declare builtins display array values in a way that allows them to be reused as assignments.
Linux shell脚本编程——本地语言设置为中文
#!/bin/bash
################################变量定义################################
defaultLanguage="zh_CN.utf8"
declare -A languagePacks
languagePacks=( ["zh_CN.utf8"]="kde-l10n-Chinese")
##语言包列表
languagePack=${languagePacks[$defaultLanguage]}
################################函数模块################################
##查看系统是否存在指定语言包
function FindLocalLanguagePackages(){
locale -a|grep $defaultLanguage echo "find $defaultLanguage" return 0 || return 1
}
##安装指定语言包
function InstallsLanguagePack(){
yum install $languagePack return 0 || return 1
}
##临时设置系统默认语言包
function TemporarilySetDefaultLanguagePack(){
LANG=$defaultLanguage echo "Temporarily Set Default Language Pack to $defaultLanguage" return 0 || return 1
}
##永久设置系统默认语言包
function SetDefaultLanguagePackage(){
localectl set-locale LANG=$defaultLanguage echo "Set Default Language Pack to $defaultLanguage" return 0 || return 1
}
################################程序流程################################
##查看系统当前语言包
[ $LANG == $defaultLanguage ] echo $LANG || FindLocalLanguagePackages
##安装指定语言包 或 临时设置系统默认语言包
[ $? == 0 ] TemporarilySetDefaultLanguagePack || InstallsLanguagePack
##永久设置系统默认语言包
[ $? == 0 ] SetDefaultLanguagePackage
##查看结果
[ $LANG == $defaultLanguage ] echo "/etc/locale.conf is `cat /etc/locale.conf`" echo "Default Language Pack to $defaultLanguage" || echo "Set Language error,Default Language Package $defaultLanguage"
##消除变量
unset defaultLanguage
unset languagePacks
unset languagePack
shell脚本中,无法获取“关联数组”(字典)的key,尝试过很多方法,输出都不对,求教
看下你使用的bash版本到没到4.0,使用指令bash --version查看
使用变量前先确认该变量是否在之前已经被定义过了 使用source 命令或 . 命令启动脚本时是不会开辟新线程的所以你在bash窗口里定义的没加local 变量 都会被脚本继承 此时你可以先删除这个变量 即定义phone 时 unset phone
SHELLDECLARE的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、SHELLDECLARE的信息别忘了在本站进行查找喔。
- 上一篇:o2o网站建站(o2o平台搭建)
- 下一篇:域名备案流程(域名申请的流程)
相关推荐
- 踏入阿里云服务器代理商之门:步骤和技巧 (怎么成为阿里云服务器代理商)
-
作为目前全球更大的云计算服务提供商之一,阿里云在中国市场的份额一直占据领导地位。如果你希望在云计算领域开展业务,成为阿里云服务器代理商可能是个不错的选择。本文将为大家详细介绍具体的步骤和技巧,帮助你成...
- 高性价比,足够优惠! 30美元起,年付美国VPS,值得拥有! (美国vps 年付)
-
近年来,随着互联网的不断发展,越来越多的网站需要使用虚拟主机服务,以提供更加稳定的服务质量和更好的访问速度。而虚拟主机的使用也因此成为了越来越普遍的一种方式。但是,在选择虚拟主机服务时,除了考虑到稳定...
- 评测美国云服务器,推荐性价比高的品牌 (美国云服务器哪个好用)
-
近年来,随着人们对于云计算的需求不断增加,云服务器也逐渐成为了企业、机构和个人等用户参与服务的主要方式之一。而在众多的云服务器品牌中,美国云服务器更是备受欢迎。而对于那些想要评测美国云服务器的用户来说...
- 群晖服务器的登录方法详解 (群晖服务器如何登陆)
-
群晖服务器是一种高效可靠的存储和共享平台,它可以提供非常多的实用功能和服务。但是,在开始使用之前,你需要登录到你的群晖服务器。在本文中,我们将详细讲解群晖服务器的登录方法。一、了解群晖服务器的基本概...
- 紧急通知:CDN服务器可能遇到故障,需及时解决! (cdn服务器可能发生故障)
-
作为一个网站管理员,CDN服务器的重要性我们再清楚不过了。最近,我们收到了来自网络运营商的紧急通知,通知我们CDN服务器可能遇到故障,需要及时解决。CDN服务器,即内容分发网络服务器,是在全球各个位...
- 办公室网络瘫痪!无法连接局域服务器怎么办? (连接不了局域服务器)
-
办公室网络瘫痪是企业中常见的问题之一。一旦网络瘫痪,会影响到员工的工作效率和企业的营运。当你打开电脑,却发现无法连接局域服务器时,这时该如何应对呢?1.检查网络连接检查电缆是否连接正确,网线是否...
- 利润吗?买云主机,能否带来收益? (买云主机能赚)
-
随着互联网的飞速发展,云计算作为一种新型的计算模式,其广泛应用在各个领域之中。其中,云主机服务是云计算的重要组成部分,已经成为很多企业选择托管的首选方式。随着云主机的发展和普及,很多人开始关注,如果购...
- .NET轻松打开FTP服务器文件夹,方便快捷管理文件 (.net打开ftp服务器文件夹)
-
在现代科技的浪潮下,越来越多的企业选择使用云服务器来存储和共享数据。FTP服务器是一个非常有用的工具,它允许用户上传、下载、删除和共享文件。然而,FTP管理文件需要一些特定技能和知识,否则操作可能会变...
- 2023企业服务器版:全面升级,助力企业发展 (2023 企业服务器版)
-
2023年,微软推出了全新的企业服务器版本,旨在为企业用户提供更为稳定、高效的IT系统支持,更好地助力企业发展。随着互联网和信息技术的飞速发展,企业面临着越来越大的信息化压力。如何建设一个高效、稳定...
- 享受超低价格!2023年付VPS,轻松搭建私人网站 (2023便宜年付vps)
-
当今时代,互联网充斥着各种各样的网站,无论是企业还是个人都会拥有一个网站,用来展示自己的产品或者知识。而搭建一个私人网站也是越来越普遍的事情。那么,如何搭建一个便捷而且又不贵的私人网站呢?本文将为大家...
- 回顾2023服务器系统:经典之作还是过时技术? (2023服务器系统)
-
2023年,微软公司推出了WindowsServer2023,这是一款非常成功的服务器操作系统,许多企业和机构使用它进行各种任务和应用程序。然而,随着时间的推移,新技术的发展以及安全漏洞的增加,2...
- 2023 Q3服务器排名发布:领先厂商与新兴品牌争夺冠军 (2023 Q3服务器排名)
-
近年来,随着互联网技术的迅速发展,服务器市场也持续升温。市场上主要的服务器品牌包括戴尔、惠普、联想、IBM等。而在这些老牌企业的竞争下,新兴的服务器品牌也在不停崛起。根据2023Q3服务器排名发布,...
- 「低成本高性能!100g云服务器价格惊喜震撼!」 (100g云服务器价格)
-
低成本高性能!100g云服务器价格惊喜震撼!现今的互联网时代,任何一家公司都需要拥有自己的网站,以便宣传公司产品、服务和品牌。一个高速、可靠的云服务器是每个公司的必备工具之一。就在不久之前,网络服务...
- 1u服务器显卡:强大性能让服务器效率提升 (1u服务器显卡)
-
1U服务器显卡:强大性能让服务器效率提升随着信息技术的飞速发展,人们对数据处理和存储的需求越来越高,尤其对企业级服务器的性能要求也越来越苛刻。随着、大数据、云计算等诸多新技术的不断涌现,服务器的效率...
- 韩国将于2023年推出云服务器服务,助力云计算技术的发展。 (2023韩国云服务器)
-
韩国将于2023年推出云服务器服务,助力云计算技术的发展随着互联网的高速发展,云计算技术已经成为了数字化时代的一项重要技术。云计算技术是一种以互联网为基础,将不同的底层服务封装成云服务器,以便用户可...
你 发表评论:
欢迎- 一周热门
-
-
大网数据:双12秒杀聚惠,湖北100G高防云低至0元/月,湖北独服务器低至210元、200G高防+50Mbps带宽
-
HostYun廉价洛杉矶三网回程CN2 GIA云服务器内测13元/月起(美国原生IP,去程10Gbps防御)
-
HostYun洛杉矶大硬盘云服务器9折22.5元/月起(240G-500G硬盘/1Gbps/10G防御)
-
大网数据、湖北高防云服务器低至39元/月起、湖北高防独服务器低至245元起(200G硬防、金盾+傲盾防CC)
-
樊云香港双程CN2及洛杉矶50G高防三网CN2 GIA云服务器9折22.5元/月起
-
spinservers圣何塞/达拉斯10Gbps带宽高配服务器月付89美元起
-
DogYun新上韩国独立服务器,E5/SSD+NVMe优惠后300元/月,自动化上架
-
tmhhost美国高防云服务器8折_CeRaNetworks机房/三网cn2直连/适合建站
-
高防服务器大网数据湖北独服务器低至210元、200G高防+50Mbps带宽
-
初忆云 – 2020年中云聚惠全场五折 BGP云服务器低至88/年,抓紧上车
-
- 互动交流
- 标签列表
- 最新评论
-
您的文章条理清晰,论述有据,说服力强。您的文章情感真挚,能够触动人心,引起共鸣。https://www.renhehui.com/renhehui/1479.h
沉醉于月色 评论于:08-09虚拟机部署好后跟物理机一样当服务器的,只是它依赖了本地物理机不要关机为前提。对于外网访问内网场景,本地内网搭建服务器后需要提供到互联网上连接访问的,比较简便的
访客 评论于:03-01- 刘中宜 评论于:11-01
- 访客 评论于:06-03
- AB资源网 评论于:05-08
- AB资源网 评论于:11-22
- AB资源网 评论于:11-22
- 頹廢了悲伤 评论于:11-15
- 南风知我意 评论于:11-15
- 心若冰凝 评论于:11-15