1.最近总结了 shell 中 function 的传递变量的几种方式
1.传递单个变量
2.传递数组变量
 
#!/bin/bash
 
#trying to pass an variable.
 
function func()
{
echo "The number of parameters is: ${#}"
for line in "$@"
do
echo "$line"
done
}
 
function func2()
{
  param1=("${!1}")
  param2=("${!2}")
  echo ${param1[*]}
  echo ${param2[*]}
}
echo "****************************************************"
#1.pass simpl variable.
func "hello"
func "hello"  "world"
func 1 2 3
 
#2.pass array variable
echo "*****************************************************"
array=(1 2 3)
strarray=(hello world)
echo "***************************************************"
func ${array[*]} ${strarray[*]}
func ${array[@]} ${strarray[@]}
 
echo "*****************************************************"
func2 array[@] strarray[@]
func2 array[*] strarray[*]
 
输出结果如下:
****************************************************
The number of parameters is: 1
hello
The number of parameters is: 2
hello
world
The number of parameters is: 3
1
2
3
*****************************************************
***************************************************
The number of parameters is: 5
1
2
3
hello
world
The number of parameters is: 5
1
2
3
hello
world
*****************************************************
1 2 3
hello world
1 2 3
hello world

shell 函数传递参数的几种方式的更多相关文章

  1. Delphi过程函数传递参数的几种方式

    Delphi过程函数传递参数的几种方式  在Delphi过程.函数中传递参数几个修饰符为Const.Var.Out. 另一种不加修饰符的为默认按值传递参数. 一.默认方式以值方式传递参数 proced ...

  2. 【delphi】Delphi过程、函数传递参数的八种方式

    Delphi过程函数传递参数的八种方式

  3. Delphi过程函数传递参数的八种方式

    今天一同事问我为什么有些过程函数里面有Var而有些没有,不解,遂到网上百度,得解.快哉,快哉. 在Delphi过程.函数中传递参数几个修饰符为Const.Var.Out.另一种不加修饰符的为默认按值传 ...

  4. asp传递参数的几种方式

    把下列代码分别加入a.asp和b.asp的<body></body>中,点提交,就可以将a.asp文本框的内容传给b.asp并显示出来 a.ASP <form actio ...

  5. Python中函数传递参数有四种形式

    Python中函数传递参数有四种形式 fun1(a,b,c) fun2(a=1,b=2,c=3) fun3(*args) fun4(**kargs) 四种中最常见是前两种,基本上一般点的教程都会涉及, ...

  6. vue-router传递参数的几种方式

    参考资料:vue.js官网  博客 vue-router传递参数分为两大类 编程式的导航 router.push声明式的导航 <router-link>编程式导航传递参数有两种类型:字符串 ...

  7. vue-router 传递参数的几种方式

    本文转载自:https://blog.csdn.net/crazywoniu/article/details/80942642 vue-router传递参数分为两大类 编程式的导航 router.pu ...

  8. JSP中页面向Action传递参数的几种方式

    <form name="ThisForm" method="POST" action="index.jsp"> form是表单, ...

  9. Mybatis传递参数的几种方式

    使用Map传递 优点:直接在sql中取出key即可 缺点:适用于小项目,不符合大公司规范 对象传递参数 优点:符合标准规范 缺点:麻烦 3.只有一个基本类型参数的情况下,直接在sql中取中 4.多个参 ...

随机推荐

  1. springboot整合 thymeleaf 案例

    1.运行环境 开发工具:intellij idea JDK版本:1.8 项目管理工具:Maven 4.0.0 2.GITHUB地址 https://github.com/nbfujx/springBo ...

  2. Alisha’s Party

    Alisha’s Party Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  3. windows server IIS启用Windows authentication

    双击打开IIS网站的authentication,如果有Windows authentication,直接右键启用即可,如果没有的话需要先安装一下Windows authentication,Micr ...

  4. 前端每日实战:124# 视频演示如何用纯 CSS 创作一只纸鹤

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/xagoYb 可交互视频 此视频是可 ...

  5. laravel5.6操作数据curd写法(查询构建器)

    laravel5.6 数据库操作-查询构建器 <?php //laravel5.6 语法 demo示例 namespace App\Http\Controllers;//命名该控制App空间下名 ...

  6. cookie字段属性解析

    一个域名下面可能存在着很多个cookie对象.如果我们用selenium的get_cookies方法,可以得到当前浏览器的多个cookie,比如: {'name': 'QCARJSESSIONID', ...

  7. /usr/bin/ld: cannot find -lgcc_s 问题解决小记

    /usr/bin/ld: cannot find -lgcc_s 问题解决小记 博客分类: Linux/Ubuntu 由于之前用wubi装的ubuntu并且只给了它10G的硬盘空间,随着学习的深入这种 ...

  8. 使用Flask+nginx+uwsgi+Docker部署python应用

    https://www.cnblogs.com/vh-pg/p/11731637.html

  9. Microsoft Azure_Fabric

    目录 目录 前言 Microsoft Azure Microsoft Azure Fabric Controller 前言 WindowsAzure是相对于全球版Microsoft Azure而言的中 ...

  10. shell脚本一一项目4

    主题:一键查看服务器使用率 cpu vmstat  suyu wa memery free disk  df -h  /dev tcp连接数 netstat cpu(){ used=$(vmstat ...