LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   I am getting bad substitution error. (https://www.linuxquestions.org/questions/linux-newbie-8/i-am-getting-bad-substitution-error-4175461263/)

rajivswe.2k7 05-09-2013 06:52 AM

I am getting bad substitution error.
 
<CODE>
date=20130201_0101
cti_check_date=$(date -d "${date//_/ } - 4 hours" +%Y%m%d_%H50)
eval "transfer_${date}_list='20130401_0150'"
eval "transfer_${date}_list="${transfer_${date}_list}\n${cti_check_date}""

echo "${transfer_${date}_list}"

</CODE>

I got the following error:

test.sh: line 4: "transfer_${date}_list="${transfer_${date}_list}\n${cti_check_date}"": bad substitution
test.sh: line 6: ${${transfer_${date}_list}}: bad substitution


Please help me.

rajivswe.2k7 05-09-2013 07:05 AM

Any help?

rajivswe.2k7 05-09-2013 07:16 AM

Anybody there?

chrism01 05-09-2013 07:58 AM

1. Odd looking code; can you explain what you're trying to do?
2. you don't need eval to assign values
3. use square brackets [ ] for code tags, not < >
https://www.linuxquestions.org/quest...do=bbcode#code
4. use 'set -xv' at the top of your code; it'll show you what's going on in detail

grail 05-09-2013 11:06 AM

I agree with the above, please explain the purpose of the code as it is completely unclear at present.

jpollard 05-09-2013 05:40 PM

${transfer_${date}_list} doesn't look valid at all - it looks like a recursive substitution-

The first level is the transfer_${date}_list to get an environment variable....

then to use that to extract its value.

If that is what you are trying to do... I think you will have to use an eval to get the final value...


All times are GMT -5. The time now is 12:47 PM.