有时需要遍历所有变量,但是如何生成变量名之后,再取到变量名里的值呢?

具体方法

测试动态变量的脚本:

#!/bin/bash

a=1
b=abc abc1='12345abc' tmp1=$(eval echo '$'${b}${a})
echo ${tmp1}
echo $(eval echo '$'${b}${a}) eval ${b}${a}='222222222' tmp2=$(eval echo '$'${b}${a})
echo ${tmp2}
echo ${abc1}
echo $(eval echo '$'${b}${a})

运行结果:

[root@localhost test]# sh aaa.sh
12345abc
12345abc
222222222
222222222
222222222

Bash Shell如何实现动态变量的更多相关文章

  1. bash shell

    Linux的shell 与windows只有一种批处理脚本不同,由于早年的Unix年代,发展者众,出现了各种不同的distribution,因此也随着不同的distribution出现了各自的shel ...

  2. Bash Shell内建命令和保留字

    Bash Shell内建命令和保留字命令含义!保留字,逻辑非:不做任何事,只做参数展开.读取文件并在shell中执行它alias设置命令或命令行别名bg将作业置于后台运行bind将关键字序列与read ...

  3. Bash Shell 获取进程 PID

    转载地址:http://weyo.me/pages/techs/linux-get-pid/ 导读 Linux 的交互式 Shell 与 Shell 脚本存在一定的差异,主要是由于后者存在一个独立的运 ...

  4. Learning The Bash Shell读书笔记(整理)

    最近搞了一本书 Learning Bash Shell,发现有人已经写了阅读笔记,我就在这边整理一下 来自blog:http://blog.sina.com.cn/n4mine Learning Th ...

  5. bash shell命令(2)

    在上篇<bash shell命令(1)>中,介绍了几种简单的linux shell命令,今天继续介绍bash shell命令 本文地址:http://www.cnblogs.com/arc ...

  6. Linux命令行–基本的bash shell命令

    启动shell: /etc/passwd:包含系统用户账户列表以及每个用户的基本配置信息 每个条目有七个字段,每个字段用冒号隔开 用户名 用户密码 用户的系统UID 用户的系统GID 用户的全名 用户 ...

  7. linux bash shell 流程控制(if/else )

    本文转自:http://blog.csdn.net/flowingflying/article/details/5069646 本文也即<Learning the bash Shell>3 ...

  8. linux BASH shell设置字体与背景颜色

    linux BASH shell下设置字体及背景颜色的方法. BASH shell下设置字体及背景颜色  echo -e "\e[31mtest\e[41m"  \e[30m 将字 ...

  9. bash shell漏洞及测试

    1.bash shell是大多数linux发行版本的默认shell命令解释器,但是最近爆出bash shell存在漏洞. 2.如果Bash是默认的系统shell,网络攻击者可以通过发送Web请求.se ...

随机推荐

  1. springboot启动时控制台不显示映射的URL

    背景 今天,第一次使用 2.2.0 版本的springboot,在访问接口时发现访问不到,于是在控制台进行 URL 搜索,发现并相关没有内容 原因 springboot版本差异,切换回 2.0.5.R ...

  2. [LeetCode] 921. Minimum Add to Make Parentheses Valid 使括号有效的最少添加

    Given a string S of '(' and ')' parentheses, we add the minimum number of parentheses ( '(' or ')', ...

  3. [LeetCode] 905. Sort Array By Parity 按奇偶排序数组

    Given an array A of non-negative integers, return an array consisting of all the even elements of A, ...

  4. [LeetCode] 673. Number of Longest Increasing Subsequence 最长递增序列的个数

    Given an unsorted array of integers, find the number of longest increasing subsequence. Example 1: I ...

  5. thinkphp5.1 - twig使用

    thinkphp5.1 - twig使用1.安装按照:https://github.com/yunwuxin/think-twigTwig Template For ThinkPHP5 安装 comp ...

  6. Docker笔记:常用服务安装——Nginx、MySql、Redis(转载)

    转载地址:https://www.cnblogs.com/spec-dog/p/11320513.html 开发中经常需要安装一些常用的服务软件,如Nginx.MySql.Redis等,如果按照普通的 ...

  7. 通过Windows实现端口转发

    转自:月光博客<通过Windows实现端口转发> 这里介绍一个使用两台云服务器访问外网的方法,一台国内服务器,一台国外服务器,国内服务器通过端口转发来用于中转,中转的好处是,服务器对服务器 ...

  8. Git拉取远程分支命令

    如果我们想从Git仓库中拉取一个分支到本地,此处假如远程分支为develop,本地要创建的分支为dev,可以使用以下命令: git init    //初始化本地Git仓库 git remote ad ...

  9. SQL Server使用加密连接SSL/TLS (转载)

    说明 应用程序通过未加密的通道与数据库服务器通信, 这可能会造成重大的安全风险.在这种情况下, 攻击者可以修改用户输入的数据, 甚至对数据库服务器执行任意 SQL 命令.例如,当您使用以下连接字符串时 ...

  10. .NET EF执行sql报数组超出了索引

    使用ef查询,写sql语句的 一般情况报数组超出了索引都认为是[i]里面的值超出了,但是执行sql报超出了索引,让人很蒙 在网上找了半天也没有结果,后来只能自己来解决了. 在异常里面能看到dbnull ...