当前位置:  技术问答>linux和unix

bash shell

    来源: 互联网  发布时间:2016-02-04

    本文导语:  find_idx() {     [ $# -eq 2 ] || return -1     local a i     eval a=("${$1[@]}")     //这个怎么理解?     i=0     for v in "${a[@]}"        //这个怎么理解?     do       [ "$v" = "$2" ] && echo $i && return  ...

find_idx()
{
    [ $# -eq 2 ] || return -1
    local a i
    eval a=("${$1[@]}")     //这个怎么理解?
    i=0

    for v in "${a[@]}"        //这个怎么理解?
    do
      [ "$v" = "$2" ] && echo $i && return
      let "i++"
    done

    echo -1
}

|
find_idx()
{
[ $# -eq 2 ] || return -1              
local a i
eval a=("${$1[@]}") #//转义,使a=数组名.$1为传入的参数名,${$1[@]}是列出数组的所有成员.${$1[@]},是不扩展开数组,("${$1[@]}")可用改成("${$1[@]}"),意思是把数组当成一个一个成员,
而不是扩展成一个字符串赋值给数组a.eval是执行后面的参数.
echo "$a" aaaaaaa
i=0
for v in "${a[@]}" ;#遍历数组 ."${a[@]}"的意思就是扩展开a数组的所有成员.
do
echo $v==$2
[ "$v" = "$2" ] && echo $i && return
let "i++"
done

echo -1
}
c()
{
b[0]="aa"             #定义个数组
b[1]="bb"
b[2]="cc"
find_idx b "bb"        #函数的第一个参数为数组名,第二个参数为要查找的数据
}

c

    
 
 

您可能感兴趣的文章:

  • linux bash shell命令:grep文本搜索工具简介
  • Ubuntu中如何配置shell(bash)的环境
  • linux bash shell命令:文本搜索工具grep中用于egrep和 grep -E的元字符扩展集
  • bash 与shell 什么关系?
  • linux bash shell命令:文本搜索工具Grep命令选项及实例
  • bash和Korn shell学哪个比较好
  • linux bash shell命令:文本搜索工具grep正则表达式元字符集(基本集)
  • bash 和Shell谁能形象化解释下?
  • bash shell 之下如何定义数组?
  • bash shell 的if 语句
  • 关于bash shell: 用set命令可以看到的信息都储存在哪?
  • bash shell 如何实现删除文件中的各行字符呢?
  • 请问如何遍历目录并拷贝文件?使用bash Shell。
  • bash shell ssh 登录后改变标题
  • Linux C编程一站式学习,高级shell Bash脚本编程指南,
  • linux 的shell(bash)中有数组吗?
  • Bash shell问题
  • bash shell菜鸟问题
  • [在线等]关于Bash shell的问题?
  • shell文件中第一行为#!/bin/bash ,运行后提示“:bad interpreter 没有那个文件或目录”是什么错误?怎么修改?
  • 急问bash shell中替换字符串中某字符为通配符的问题。
  •  
    本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
    本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐
  • . ./.bash_file 与 ./.bash_file的区别?
  • 为什么每次启动bash都出现bash:test:a:binary operaotr expected
  • linux RHEL 5.6 在root用户下. .bash_profile 或source .bash_profile 报错
  • 如何在ubunt下面安装两个bash
  • bash 不能使用括号,求助
  • 如何在redhat下安装bash?
  • 请问root的bash的环境变量放在哪个文件中啊?
  • linux(redhat9)中在哪里设环境变量,.bash_profil在哪里啊?
  • BASH Debugger
  • .bashrc和.bash_profile有什么区别
  • . /root/.bash_profile
  • Bash架构问题
  • bash的控制终端
  • -bash-3.2# Argument list too long 到底是怎么回事呀?
  • .bash_profile
  • 有点bash的小问题。请教。
  • bash的跳转问题
  • 【求助】solaris8系统上安装bash 报错
  • 请问linux中bash,ls等工具源代码目录在哪里?
  • 在dos和bash下字符编码是否有区别


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3