shell脚本 数组操作报Syntax error: "(" unexpected
2015-12-10 09:31
651 查看
#!/bin/sh
脚本:
var="get the length of me"
var_arr=($var)
for i in var_arr; do echo "$i"; done
执行时,会报错Syntax error: "(" unexpected
这与你实际使用的shell有关,用ls -l /bin/*sh查看:
-rwxr-xr-x 1 root root 986672 4月 24 2014 /bin/bash
-rwxr-xr-x 1 root root 112204 2月 19 2014 /bin/dash
lrwxrwxrwx 1 root root 4 8月 4 2014 /bin/rbash -> bash
lrwxrwxrwx 1 root root 4 8月 4 2014 /bin/sh -> dash
lrwxrwxrwx 1 root root 7 8月 4 2014 /bin/static-sh -> busybox
这里sh被重定向到dash,dash不支持数组。
1)执行 bash example.sh;
2)将脚本第一行改为 #!/bin/bash,执行./example.sh
脚本:
var="get the length of me"
var_arr=($var)
for i in var_arr; do echo "$i"; done
执行时,会报错Syntax error: "(" unexpected
这与你实际使用的shell有关,用ls -l /bin/*sh查看:
-rwxr-xr-x 1 root root 986672 4月 24 2014 /bin/bash
-rwxr-xr-x 1 root root 112204 2月 19 2014 /bin/dash
lrwxrwxrwx 1 root root 4 8月 4 2014 /bin/rbash -> bash
lrwxrwxrwx 1 root root 4 8月 4 2014 /bin/sh -> dash
lrwxrwxrwx 1 root root 7 8月 4 2014 /bin/static-sh -> busybox
这里sh被重定向到dash,dash不支持数组。
1)执行 bash example.sh;
2)将脚本第一行改为 #!/bin/bash,执行./example.sh
相关文章推荐
- xshell 自动换行设置
- shell脚本练习题
- shell脚本练习题
- -bash: vim: command not found.
- SHELL笔记-1
- shell编程Linux中批量创建用户
- BashShell基础
- shell脚本中生成的spool文件没有执行的语句
- 用shell脚本实现自动分区
- Shell Script demo_01
- shell获取指定日期前(后)N天日期
- Hbase常用的shell命令
- linux shell脚本查找重复行/查找非重复行/去除重复行/重复行统计
- expect实现交互式输入
- 希尔排序(ShellSort)
- Linux shell脚本
- shell小例子
- Linux使用Shell脚本实现ftp的自动上传下载
- 关于BASH中变量内容的删除、取代与替换
- linux shell if