原文地址:http://bbs.chinaunix.net/thread-3628456-1-1.html

总结地址:https://www.cnblogs.com/binbinjx/p/5680214.html

配置文件config内容如下

  1. ID=
  2. IP=192.168.3.154
  3. Name=test

方法一,利用sed解析文本,提取配置信息

  1. id=`sed '/^ID=/!d;s/.*=//' urfile`
  2. ip=`sed '/^IP=/!d;s/.*=//' urfile`
  3. name=`sed '/^Name=/!d;s/.*=//' urfile`
  4. echo $id
  5. echo $ip
  6. echo $name

方法二,利用eval方法解析

  1. while read line;do
  2. eval "$line"
  3. done < config
  4. echo $ID
  5. echo $IP
  6. echo $Name

方法三,直接将配置信息加载到session的环境变量中

  1. source config
  2.  
  3. echo $ID
  4.  
  5. echo $IP
  6. 192.168.3.154
  7. echo $Name
  8. test

shell 读取配置文件的方法的更多相关文章

  1. Shell读取配置文件的方法

    参考:http://www.cnblogs.com/binbinjx/p/5680214.html 做批量软件安装自动化时,都喜欢用配置文件的方式改变参数,那怎么通过shell读取配置文件的配置呢?参 ...

  2. Log4j 2.0读取配置文件的方法

    log4j中配置日志文件存放的位置不一定在src下面,即根目录下.这个时候我们需要解决如何加载配置文件的问题.在log4j1.x中解决的方法就比较多了.如:PropertyConfigurator.c ...

  3. 面试突击75:SpringBoot 有几种读取配置文件的方法?

    Spring Boot 中读取配置文件有以下 5 种方法: 使用 @Value 读取配置文件. 使用 @ConfigurationProperties 读取配置文件. 使用 Environment 读 ...

  4. java中读取配置文件的方法

    转自:http://blog.csdn.net/stypace/article/details/38414871 一.使用org.apache.commons.configuration 需要使用的是 ...

  5. linux shell读取配置文件

    配置文件CoverageInfo FTP_URL=ftp://svn-fb.sicent.com:21/jenkins/Jifei_Repo/OL-2/IDC_Platform/bar_seats_c ...

  6. Spring ClassPathXmlApplicationContext和FileSystemXmlApplicationContext读取配置文件的方法

    先说:ClassPathXmlApplicationContext 这个类,默认获取的是WEB-INF/classes/下的路径,也就是在myeclipse的src下的路径,所以用这个是获取不到WEB ...

  7. ASP .NET CORE 读取配置文件的方法

    老式的config文件在ASP.net core2.0中变成了appsettings.json,如果想要读取自定义配置,可以写如下代码 { "Logging": { "I ...

  8. java读取配置文件的方法

    1. Preferences类 这个主要是设置个人喜好.它的数据一般存在系统目录或是用户目录.还可以操作注册表. 2. Properties类 保存键值对.可以指定路径. 3. commons con ...

  9. shell 读取配置文件的用法

    https://blog.csdn.net/qq_36684665/article/details/81134179 亲测有用!

随机推荐

  1. sqlServer 获取最新的一条数据

    SQL语句获取最新一条的数据 * from tra.dbo.订单 order by 下单时间 desc --时间倒序排列取第一条 select * from tra.dbo.订单 where 下单时间 ...

  2. Python输出和输入

    一.input()函数 在 Python 中,使用内置函数 input()可以接收用户的键盘输入. input()函数的基本用法如 下: variable = input("提示文字") 其中,var ...

  3. MySQL服务使用

    MySQL服务使用 1. 启动服务 启动服务: service mysql start 或者 sudo /etc/init.d/mysql start 2. 关闭服务 关闭服务: service my ...

  4. 从零开始的cve分析- cve-2016-0095 简易记录

    0x00 前言 看k0shl大佬的SSCTF pwn450 Windows Kernel Exploitation Writeup一文,试着写一个x64下的poc. poc地址:https://git ...

  5. C# -- 随机数产生的字母金字塔

    C# -- 随机数产生的字母金字塔 1. 代码实现: static void Main(string[] args) { showNpoint(); Console.ReadKey(); } priv ...

  6. June 4. 2018 Week 23rd Monday

    Don't criticize what you can't understand. 不懂的,不要随意批判. From Bob Dylan. Don't criticize what you can' ...

  7. C# → 数据库

    Database: public static class dbconnection{ static string cons = "data source = (local) ;initia ...

  8. nodejs websocket

    <script src="https://cdn.socket.io/socket.io-1.4.5.js"></script> <script ty ...

  9. E. Magic Stones CF 思维题

    E. Magic Stones time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  10. 「AHOI / HNOI2017」单旋

    「AHOI / HNOI2017」单旋 题目链接 H 国是一个热爱写代码的国家,那里的人们很小去学校学习写各种各样的数据结构.伸展树(splay)是一种数据结构,因为代码好写,功能多,效率高,掌握这种 ...