Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
164 views
in Technique[技术] by (71.8m points)

shell - how to read a variable from a file to a Unix script in Unix

I have a text file as below:

[Global]

$DBConnection_prd_load=GETDB

$$SURVEY_TYPE=ALL

$$VENDOR_SURVEY_ID=5

$$PROD_EMAIL=users@tnnnet.com

$$LASTRUNDATE=10/24/2013

I want to pass above file $$LASTRUNDATE value to below script. Pl help. And also replace / with _.

#! /bin/ksh

export SRCDIR=/informat/PowerCenter/9.1.0/server

export TGTDIR=/informat/PowerCenter/9.1.0/server/infa

export FILEDT=**$$LASTRUNDATE**

cd ${SRCDIR}

export GET_FNAME=AllResponses_${FILE_NUM}_${FILEDT}*.txt

        if [ -f ${GET_FNAME} ]; then

                cp ${SRCDIR}/${GET_FNAME} ${TGTDIR}

Can you pl also let me know how to replace '' with '_' ?

Friend..one more small favour..is it possible to add 1 day to date that we get in the above variable..?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could just use backticks.

This would produce the output:

cat mytextfile | grep '$$LASTRUNDATE=' | sed 's/$$LASTRUNDATE=//g'| sed 's///_/g'

And this would allow me to store it:

export FILEDT=`cat mytextfile | grep '$$LASTRUNDATE=' | sed 's/$$LASTRUNDATE=//g' | sed 's///_/g'`

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...