Sponsored Content
Top Forums Shell Programming and Scripting How to parse the variable in .mk file? Post 303002906 by bakunin on Monday 4th of September 2017 11:02:28 PM
Old 09-05-2017
Quote:
Originally Posted by ricky-row
I am passing a variable in .mk file as

Code:
NEED="TEST=Name WORK=Ps DEL=let"

I need to echo and export each variable like TEST, WORK. DEL
If:
1) your input is guaranteed to be properly delimited by single blanks always,

2) the item=value pairs will contain no further spaces

then the following may work, provided that you use a common shell (and not Ubuntus standard shell dash). Notice that you may need to add additional tests, trims and other measures to this skeleton because real-world input might not be as well-behaved as is ideal:

Code:
input="$1"
buf=""

while [ -n "$input" ] ; do
     buf="${input##* }"               # these two lines chop off 
     input="${input% ${buf}}"         # one item=value pair after the other

     echo "$buf"
     eval export "$buf"
done

Note also that the input string is tokenized backwards, so that the input a=b c=d e=f will result in:

Code:
export e=f
export c=d
export a=b

in this order.

I hope this helps.

bakunin
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

parse a string variable

Hello all, need a little help. I have an input variable such as ARGV which equals something like /use/home/name/script/test.dat I need to be able to get just the "test.dat" (i.e. the file name) at the end of the directory and the directory can be anything and any length. To put it another... (3 Replies)
Discussion started by: methos
3 Replies

2. Shell Programming and Scripting

parse variable

I have a variable (it is a date actually -> 2007-01-03) which would be passed in as parameter, what I want is to parse in and put year, month, and day in separate variables, I have tried the following but doesn't work echo $dt | awk -F- '{print $1 $2 $3}' | read y m d Thanks in... (2 Replies)
Discussion started by: mpang_
2 Replies

3. Shell Programming and Scripting

Parse String from a Variable

Hello, Is there a quick way to parse the values from a variable? The variable has the following sample input: TA= The values of the TA variable is not fixed/hardcoded Basically I need to get the IV_Test and PF_SAPP_FWK values. I created a script that first use sed to remove ,... (3 Replies)
Discussion started by: racbern
3 Replies

4. Shell Programming and Scripting

how to parse value of the variable

I have a variable which has a full path to the file, for example : A=/t1/bin/f410pdb Does anybody know the command to parce this variable and assign the result to 3 other variables so each subdirectory name will be in a new variable like this B=t1 C=bin D=f410pdb Many thanks -A (5 Replies)
Discussion started by: aoussenko
5 Replies

5. Shell Programming and Scripting

Parse text file in shell & store to variable

Hi, I need to parse a simple text file like below and store the word that starts with BR* to a variable say $BRno. I need to do this in sh script. NOTE: the length of the numbers following BR is in constant. And there is only 1 BRXXX in a file at a given time. .txt file: BR276828... (1 Reply)
Discussion started by: script2010
1 Replies

6. Shell Programming and Scripting

Parse file and copy value to variable in sh script.

Hi, I need to parse a simple text file like below and store the word that starts with BR* to a variable say $BRno. I need to do this in sh script. NOTE: the length of the numbers following BR is not constant (eg: it could be BR1234 or BR22233). And there is only 1 BRxxxxx in a file at a given... (6 Replies)
Discussion started by: script2010
6 Replies

7. Shell Programming and Scripting

Parse config file data to script variable

I have a script with few pre defined variables. Also have a config file. Something like this. # config file # Define Oracle User MOD1_TAG=abcde MOD2_TAG=xyzabc MOD3_TAG=def I need to parse the config file and have each of the value copied to different variables. Please suggest what... (1 Reply)
Discussion started by: souryadipta
1 Replies

8. Shell Programming and Scripting

How to parse xml file in variable-string?

In the wake of the post: how-parse-following-xml-file Thank you for the very useful chakrapani response 302355585-post4 ! A close question. How to pass a file to xmllint in variable? For example, let it be: NEARLY_FILE='<?xml version="1.0" encoding="iso-8859-1"?><html><set label="09/07/29"... (0 Replies)
Discussion started by: OleM2k
0 Replies

9. Shell Programming and Scripting

Help about parse the variable

I'm using bash the code is QEMU_CMD="qemu-system-x86_64 -smp 2 -m 512 $QEMU_PARAMETER -hda $GUEST_IMAGE -kernel $GUEST_KERNEL -append \"root=/dev/hda rw console=ttyS0,115200 ip=$IP_PARAMETER \" -nographic" echo "..............................." echo "qemu command is... (9 Replies)
Discussion started by: yanglei_fage
9 Replies

10. UNIX for Beginners Questions & Answers

Grepping for one variable while using awk to parse an associated variable

Im trying to search for a single variable in the first field and from that output use awk to extract out the lines that contain a value less than a value stored in another variable. Both the variables are associated with each other. Any guidance is appreciated. File that contains the... (6 Replies)
Discussion started by: ncwxpanther
6 Replies
SETBUF(3)						     Library Functions Manual							 SETBUF(3)

NAME
setbuf, setvbuf - assign buffering to a stream SYNOPSIS
#include <stdio.h> int setbuf(FILE *stream, char *buf) int setvbuf(FILE *stream, char *buf, int type, size_t size) DESCRIPTION
The three types of buffering available are unbuffered, block buffered, and line buffered. When an output stream is unbuffered, information appears on the destination file or terminal as soon as written; when it is block buffered many characters are saved up and written as a block; when it is line buffered characters are saved up until a newline is encountered or input is read from stdin. Fflush (see fclose(3)) may be used to force the block out early. Normally all files are block buffered. A buffer is obtained from malloc(3) upon the first getc or putc(3) on the file. If the standard stream stdout refers to a terminal it is line buffered. The standard stream stderr is always unbuffered. Setbuf is used after a stream has been opened but before it is read or written. The character array buf is used instead of an automati- cally allocated buffer. If buf is the constant pointer NULL, input/output will be completely unbuffered. A manifest constant BUFSIZ tells how big an array is needed: char buf[BUFSIZ]; Setvbuf, an alternate form of setbuf, is used after a stream has been opened but before it is read or written. It has three uses, depend- ing on the value of the type argument: setvbuf(stream, buf, _IOFBF, size) Causes input/output to be fully buffered using the character array buf whose size is determined by the size argument. If buf is the constant pointer NULL, then an automatically allocated buffer will be used. setvbuf(stream, buf, _IOLBF, size) Like above, except that output will be line buffered, i.e. the buffer will be flushed when a newline is written, the buffer is full, or input is requested. setvbuf(stream, buf, _IONBF, size) Causes input/output to be completely unbuffered. Buf and size are ignored. A file can be changed between unbuffered, line buffered, or block buffered by using freopen (see fopen(3)) followed by the appropriate setvbuf call. SEE ALSO
fopen(3), getc(3), putc(3), malloc(3), fclose(3), puts(3), printf(3), fread(3). 4th Berkeley Distribution May 12, 1986 SETBUF(3)
All times are GMT -4. The time now is 01:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy