I needs to update the sourced config file in shell script in end of the script execution. I have default date in date_cfg.lkp file.
'''
sdate=2021-12-09
'''
My shell script file accept date as parameter and it should increment the date and update that date in above date_cfg.lkp file and it works if I don't source the file but if I do source the lkp file in script it does not updating and also same behavior in command line aswell.:
'''
#!/usr/bin/bash
date1=$1
cfg=~/date_cfg.lkp
source $cfg
date1=$(date -d"$date1 1 day" "%Y%m%d")
date1=$(date1 -d $date1 "%Y-%m-%d")
echo $date1
echo $cfg_date
sed -c -i "s/\($sdate *= *\).*/\1$date1/" $cfg
'''
Please help me updating the sdate field stored in the lkp file with incremented date in script while sourcing and please note I needs to source the file to read some other fields.
CodePudding user response:
Try to modify the last line as follows.
sed -c -i "s/$sdate/$date1/" $cfg
CodePudding user response:
your sed command isn't good:
sed -i "/sdate=/ s/.*/sdate=$date1/" date_cfg.lkp
What is -c in the command ? I haven't this arg.