Results 1 to 3 of 3
Hi,
I am writing a bash script, Here i am using following commands to generate logs :-
cp -rf ${LOGFILE} ${VALUE}.${TASK}.${ENVIRONMENT}.`date +%Y%m%d%H%M%S`.log
Here at my case TASK would be of ...
- 09-27-2008 #1Just Joined!
- Join Date
- Jan 2008
- Posts
- 20
Strange Issue
Hi,
I am writing a bash script, Here i am using following commands to generate logs :-
cp -rf ${LOGFILE} ${VALUE}.${TASK}.${ENVIRONMENT}.`date +%Y%m%d%H%M%S`.log
Here at my case TASK would be of two types - Do or Don't
If i will use Do it will generate a log file like :- 2008.Do..20080827180934
because in my script if i use Do Task then there is no value set for ENVIRONMENT Variable, And if i use Don't It will assign a variable ENVIRONMENT and i am getting valid log file with proper names i.e.
2008.Don't.ob.20080827180934
I want to remove extra . from 008.Do..20080827180934 so that i can get 2008.Do.20080827180934
Can somebody please help me.
Great Thanks in advance,
Inder
- 09-28-2008 #2Linux Newbie
- Join Date
- Jan 2008
- Location
- UK
- Posts
- 211
Hi,
An idea that I would do is to write it as a script witha conditional check so that it escapes the extra dot when certain input is entered or values of the variables.
wowbag1
- 10-01-2008 #3Linux User
- Join Date
- May 2008
- Location
- NYC, moved from KS & MO
- Posts
- 251
Replace the dot right after ${ENVIRONMENT} with
${ENVIRONMENT:+.}
that is,
cp -rf ${LOGFILE} ${VALUE}.${TASK}.${ENVIRONMENT}${ENVIRONMENT:+.}`date +%Y%m%d%H%M%S
${ENVIRONMENT:+.} returns . if $ENVIRONMENT exists and is not null, otherwise returns null.
More variable mangling can be found at Variable Mangling in Bash with String Operators LG #57


Reply With Quote