从文件中读取一个值到一个变量 [英] Read a value from a file into a variable

查看:117
本文介绍了从文件中读取一个值到一个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是使Windows和我想从文件中读取几个值在Makefile中作为变量使用。

我有包括如下的文件:

  / *注释* /
#定义SOME_STRINGABCDE/ *注释,* /
#定义BLANK_STRING/ *注释* /
#定义SOME_VERSION 01.01a01

我想在我的makefile两个变量来结束。一组为 ABCDE ,另一组为 01.01a01

这也可以使用一些从Makefile中所谓的bash命令来完成。我是新来的makefile,bash和计算器,请多多包涵!

感谢

斯蒂芬


解决方案

 所有:
  回声$(SOME_VERSION)进口:INPUT_FILE
  SED -nS / ^#定义\\([^] * \\)\\(* [^] ** \\)/ \\ 1 = \\ 2 / P'INPUT_FILE>进口包括进口

I'm using make in Windows and I'd like to read a couple of values from a file to use as variables in the makefile.

I have a file that includes the following lines:

/* A comment */
#define SOME_STRING "ABCDE"

/* A comment         "     " */
#define BLANK_STRING "     "

/* A comment */
#define SOME_VERSION 01.01a01

I'd like to end up with two variables in my makefile. One set to ABCDE and the other set to 01.01a01.

This could also be done using some bash commands called from within the makefile. I'm new to makefiles, bash and stackoverflow so please bear with me!

Thanks

Stephen

解决方案

all:
  echo $(SOME_VERSION)

imports: input_file
  sed -n 's/^#define \([^ ]*\) \("*[^"]*"*\)/\1=\2/p' input_file > imports

include imports

这篇关于从文件中读取一个值到一个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆