LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-09-2013, 07:52 AM   #1
rajivswe.2k7
LQ Newbie
 
Registered: Apr 2013
Posts: 15

Rep: Reputation: Disabled
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.
 
Old 05-09-2013, 08:05 AM   #2
rajivswe.2k7
LQ Newbie
 
Registered: Apr 2013
Posts: 15

Original Poster
Rep: Reputation: Disabled
Any help?
 
Old 05-09-2013, 08:16 AM   #3
rajivswe.2k7
LQ Newbie
 
Registered: Apr 2013
Posts: 15

Original Poster
Rep: Reputation: Disabled
Anybody there?
 
Old 05-09-2013, 08:58 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
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
 
Old 05-09-2013, 12:06 PM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,252

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
I agree with the above, please explain the purpose of the code as it is completely unclear at present.
 
Old 05-09-2013, 06:40 PM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
${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...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Why I get bad substitution when using eval? 915086731 Linux - General 1 08-19-2011 10:41 AM
string replace - bad substitution xombboxer Linux - Newbie 1 05-01-2011 08:46 AM
Bad substitution error. Stripping unnecessary word from song title. Dafydd Programming 14 12-22-2010 09:11 PM
[SOLVED] /etc/init/d/functions - Bad Substitution error axisofevil Linux - Newbie 7 04-06-2010 01:34 PM
LFS Chapter 5.7 bad substitution MP123 Linux From Scratch 4 02-07-2007 03:08 AM


All times are GMT -5. The time now is 08:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration