linux – 未找到Bash中的数组
发布时间:2020-05-23 10:55:19 所属栏目:Linux 来源:互联网
导读:我试图在bash中声明一个数组,但是当代码运行时它说它找不到数组.我试图以几种不同的方式写出数组的声明,但似乎无论我如何声明它我都无法使它工作.我最初试图宣布它为: candidate[1]= 0candidate[2]= 0candidate[3]= 0 返回的错误消息是: votecalculation.sh
|
我试图在bash中声明一个数组,但是当代码运行时它说它找不到数组.我试图以几种不同的方式写出数组的声明,但似乎无论我如何声明它我都无法使它工作.我最初试图宣布它为: candidate[1]= 0 candidate[2]= 0 candidate[3]= 0 返回的错误消息是: votecalculation.sh: 13: candidate[1]=: not found votecalculation.sh: 14: candidate[2]=: not found votecalculation.sh: 15: candidate[3]=: not found 在此之后我尝试了另一种在线发现的解决方案 ARRAY=( 'can1' 'can2' 'can3' ) 使用它时会返回此错误: votecalculation.sh: 12: Syntax error: "(" unexpected
我是Bash的新手,我对阵列感到很困惑.我需要一些特定的方式来声明一个数组,还是我只是完全错了? 解决方法#!/bin/bash
myarray[0]=hello
myarray[1]=world
echo ${myarray[0]}
echo ${myarray[1]}
保存到helloworld.bash 执行使用. ./helloword.bash (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 在Linux上使用软件RAID和LVM时,哪些IO调度程序和预读设置受
- nginx 启动时报错Starting nginx (via systemctl): nginx.s
- debian – 在LVM / DRBD调整大小后,df报告的信息不正确
- linux – 当我在shell脚本中使用cat命令时,如何在文件末尾保
- linux – 保护安全SFTP服务器的文件系统
- linux – 如何找到unix socket连接的另一端?
- php – Magento扩展404错误
- osx – 如何从一开始就跟踪程序,而不以root身份运行
- linux – 在64位机器上运行valgrind 32位二进制文件
- c – 监听用户在linux中的GUI程序
