LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   linux bash - how to use a dynamic parameter in shell parameter expansion expression (http://www.linuxquestions.org/questions/linux-general-1/linux-bash-how-to-use-a-dynamic-parameter-in-shell-parameter-expansion-expression-475808/)

nickleus 08-21-2006 04:57 AM

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

nickleus 08-21-2006 05:37 AM

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

unSpawn 08-21-2006 05:54 AM

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.


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