#!/bin/bash
# array variable to function test function testit {
local newarray
newarray=("$@")
echo "The new array value is: ${newarray[*]}"
} myarray=( )
echo "The original array is ${myarray[*]}"
testit ${myarray[*]}

注意:

function testit { 中函数名 testit 和 { 中间是必须加上空格的。

myarray=( ) 中的 ( ) 两边不能加上双引号,等号两边不能加上空格的。

运行 sh test.sh 输出为:

The original array is
The new array value is:

shell script数组使用函数输出的更多相关文章

  1. Linux基础之-shell script(变量,运算符,流程控制,函数)

    一.shell script Shell 脚本(shell script),是一种为shell编写的脚本程序.业界所说的shell通常都是指shell脚本,但读者朋友要知道,shell和shell s ...

  2. 03 . Shell数组和函数

    Shell数组 简介 数组中可以存放多个值.Bash Shell 只支持一维数组(不支持多维数组),初始化时不需要定义数组大小(与 PHP 类似). 与大部分编程语言类似,数组元素的下标由0开始. S ...

  3. 声明数组变量/// 计算所有元素的总和/打印所有元素总和/输出/foreach循环/数组作为函数的参数/调用printArray方法打印

    实例 下面是这两种语法的代码示例: double[] myList; // 首选的方法 或 double myList[]; // 效果相同,但不是首选方法 创建数组 Java语言使用new操作符来创 ...

  4. 101-PHP二维数组的元素输出三,封装成函数

    <?php $arr=array(array(76,87,68), array(65,89,95), array(90,80,66), array(90,95,65),5,234,56,'Hel ...

  5. Linux&shell之高级Shell脚本编程-创建函数

    写在前面:案例.常用.归类.解释说明.(By Jim) 使用函数 #!/bin/bash # testing the script function myfun { echo "This i ...

  6. 菜鸟教程之学习Shell script笔记(上)

    菜鸟教程之学习Shell script笔记 以下内容是,学习菜鸟shell教程整理的笔记 菜鸟教程之shell教程:http://www.runoob.com/linux/linux-shell.ht ...

  7. linux shell 进阶篇、shell脚本编程-创建函数

    使用函数 #!/bin/bash # testing the script function myfun { echo "This is an example of a function&q ...

  8. shell script简单笔记

    变量 shell script是一种脚本语言,变量的定义是通过 myName=HYB 这样的形式定义的. 当存在空格时,可以通过双引号或单引号将其变为字符串.双引号不进行转义,单引号将内容进行转义为一 ...

  9. shell script的简单使用

    shell script的简单介绍 shell变量 1.命名规则 命名只能使用英文字母,数字和下划线,首个字符不能以数字开头 中间不能有空格,可以使用下划线(_) 不能使用标点符号. 不能使用bash ...

随机推荐

  1. peak num

    class Solution {public: int findPeakElement(vector<int>& nums) {    int i=0;    int n=nums ...

  2. Shipyard远程API

    1.鉴权模块 1.1 Login,获取token POST  http://192.168.31.149:8080/auth/login Headers Content-Type: applicati ...

  3. CGRectGet系列

    CGRectGetHeight返回label本身的高度 CGRectGetMinY返回label顶部的坐标 CGRectGetMaxY 返回label底部的坐标 CGRectGetMinX 返回lab ...

  4. C# winform 中MessageBox用法大全(附效果图) (转载+说明)

    声明:这篇文章是转载的转载的,由于原作者的博客被关闭 我就不再列出了,提前先说明下,if语句中的判断有些太长,建议提前声明一个变量, DialogResult MsgBoxResult;        ...

  5. python: linux下安装redis

    Python连接时报拒绝连接,需要重装redis: 1) 卸载redis sudo apt-get remove redis-server sudo apt-get autoremove 2)编译安装 ...

  6. CSS选择器及其优先级

    一:一些普通的选择器 <!DOCTYPE html> <html> <head lang="en"> <meta charset=&quo ...

  7. 链表——PowerShell版

    链表是由一系列节点串连起来组成的,每一个节点包括数值部分和指针部分,上一节点的指针部分指向下一节点的数值部分所在的位置. 在C语言中我们有两种方式来定义链表—— 1.定义结构体:来表示链表中的节点,节 ...

  8. HTML 5 Web Sockets应用初探

    转载不错的http://developer.51cto.com/art/201008/217874.htm

  9. Codeforces Round #260 (Div. 2) B

    Description Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expre ...

  10. 2016年11月18日 星期五 --出埃及记 Exodus 20:9

    2016年11月18日 星期五 --出埃及记 Exodus 20:9 Six days you shall labor and do all your work,六日要劳碌作你一切的工,