LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-21-2006, 03:57 AM   #1
nickleus
Member
 
Registered: Nov 2004
Location: Noreg
Distribution: ubuntu
Posts: 107

Rep: Reputation: 15
linux bash - how to use a dynamic parameter in shell parameter expansion expression


say that i want to use parameter expansion to parse out characters 7 and 8 in a string, but i want to generate that string dynamically inside the parameter expansion phrase. how do i do that?

format:
Code:
${parameter:offset:length}
what parameter will look like:
20060822105030

i want what is bold. this works fine on the command line:
Code:
export imorgen=$(date --date=tomorrow +%Y%m%d%H%M);echo ${imorgen:6:2}
or in a script file:
Code:
IMORGEN=$(date --date=tomorrow +%Y%m%d%H%M)
echo "today is day number ${imorgen:6:2}"
but i can't seem to figure out how to do this dynamically (without setting a variable) inside the parameter expansion phrase. i've tried this, but it doesn't work:
Code:
${$(date --date=tomorrow +%Y%m%d%H%M):6:2}
i get a bad substitution error. anybody know how to do this?

thanks in advance =)
Nick

Last edited by nickleus; 08-21-2006 at 03:59 AM.
 
Old 08-21-2006, 04:37 AM   #2
nickleus
Member
 
Registered: Nov 2004
Location: Noreg
Distribution: ubuntu
Posts: 107

Original Poster
Rep: Reputation: 15
ok, i just realized i could do this to accomplish the same thing:
Code:
$(date --date=tomorrow +d%)
but i'm still curious as to how to dynamically generate a parameter for a shell parameter expansion expression so anybody who knows how to do that please let me know =) thanks.

Nick
 
Old 08-21-2006, 04:54 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
but i can't seem to figure out how to do this dynamically (without setting a variable) inside the parameter expansion phrase.
AFAIK you can't.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
trouble with positional parameter $0 on bash. linux distro: ubuntu breezy linrookie Linux From Scratch 2 05-07-2006 12:22 PM
bash parameter indirection possible? kornelix Programming 5 11-30-2005 08:35 AM
setting up scp alias under bash - parameter passing problem gjr Linux - Newbie 4 06-08-2005 06:38 AM
bash: pass a parameter to xview nimra Programming 2 06-28-2004 09:18 PM
Bash function parameter Misel Programming 2 05-17-2003 11:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

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