syntax error near unexpected token `local'

来源:互联网 发布:wp7软件下载 编辑:程序博客网 时间:2024/06/05 22:49

问题描述

function testit{     local newarray     newarray=($(echo $@))     echo "the new array is ${newarray[*]}"}myarray=(1 2 3 4)echo the original array is ${myarray[*]}testit ${myarray[*]}

运行这样一段代码出现了问题,报错syntax error near unexpected token `local’

解决方法

在shell中,函数名称和中括号之间需要有空格,即testit {

function testit {     local newarray     newarray=($(echo $@))     echo "the new array is ${newarray[*]}"}
阅读全文
0 0
原创粉丝点击