LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 06: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, 07:05 AM   #2
rajivswe.2k7
LQ Newbie
 
Registered: Apr 2013
Posts: 15

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

Original Poster
Rep: Reputation: Disabled
Anybody there?
 
Old 05-09-2013, 07:58 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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, 11:06 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

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

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



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 09:41 AM
string replace - bad substitution xombboxer Linux - Newbie 1 05-01-2011 07:46 AM
Bad substitution error. Stripping unnecessary word from song title. Dafydd Programming 14 12-22-2010 08:11 PM
[SOLVED] /etc/init/d/functions - Bad Substitution error axisofevil Linux - Newbie 7 04-06-2010 12:34 PM
LFS Chapter 5.7 bad substitution MP123 Linux From Scratch 4 02-07-2007 02:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:52 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
Open Source Consulting | Domain Registration