[Seek Help] shell定义数组提示错误
Tofloor
poster avatar
weboob
deepin
2021-12-03 00:43
Author
#!/bin/bash

# 获取当前鼠标位置
#a=($(xdotool getmouselocation))
a=(a b c d)
echo ${a[1]}

定义数组a,结果提示(符号错误,

image.png

这是为啥呢,看网上例子都是用的括号,自动解析 空格 分隔符的

求指点


感谢各位的帮助,原来是我执行脚本的命令有问题。一直用 sh xxx.sh执行的,原来要用bash命令blush

此贴完结(2021-12-08)

Reply Favorite View the author
All Replies
liwl
deepin
2021-12-03 00:51
#1

a=a,你把数组名换成array

array=()

Reply View the author
babyfengfjx
Super Moderator
CQA
2021-12-03 01:12
#2

感觉没毛病啊:image.png

Reply View the author
DebuggerX
deepin
2021-12-03 01:16
#3

image.png

用bash执行脚本即可

第一行你写的貌似是中文感叹号,要用英文的,推荐的写法是:

#!/usr/bin/env bash
Reply View the author
jianghuchuan
deepin
2021-12-03 03:13
#4

没问题的image.png

Reply View the author
enforcee
deepin
2021-12-03 06:26
#5

sh是sh

bash是bash

你要用bash执行,不要用sh执行,不信你自己打一个sh看看是什么shell

blush

debian的sh链接的是dash,专门欺负少打俩字的新手

Reply View the author
banemon
deepin
2021-12-03 12:56
#6

=两边不要有空格

Reply View the author
wu******67@gmail.com
deepin
2021-12-03 23:56
#7
wuhao@wuhao-Thurley:~$ sh a.sh 
a.sh: 5: Syntax error: "(" unexpected
wuhao@wuhao-Thurley:~$ . a.sh 
b
​
Reply View the author
weboob
deepin
2021-12-08 21:07
#8
liwl

a=a,你把数组名换成array

array=()

感谢回复,我用的sh执行的,用bash没问题,新手😂

Reply View the author
weboob
deepin
2021-12-08 21:09
#9
babyfengfjx

感觉没毛病啊:image.png

执行命令有问题,哈哈(用的sh)

Reply View the author
weboob
deepin
2021-12-08 21:09
#10
DebuggerX

image.png

用bash执行脚本即可

第一行你写的貌似是中文感叹号,要用英文的,推荐的写法是:

#!/usr/bin/env bash

原来要用bash。。。。。

Reply View the author
weboob
deepin
2021-12-08 21:10
#11
enforcee

sh是sh

bash是bash

你要用bash执行,不要用sh执行,不信你自己打一个sh看看是什么shell

blush

debian的sh链接的是dash,专门欺负少打俩字的新手

真愁人,原来是酱紫yeah

Reply View the author
enforcee
deepin
2021-12-08 22:21
#12
weboob

真愁人,原来是酱紫yeah

也不知该怪debian的奇妙设计还是怪用其他发行版做演示的教程

我当年还是小白时没少被坑

joy

Reply View the author