Evaluate Variable At Runtime


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Evaluate Variable At Runtime
# 1  
Old 07-22-2013
Lightbulb Evaluate Variable At Runtime

Hi,

I am trying to set a variable that has time the format desired. And my intention is to echo variable (instead of actual date command) everytime I like to echo date. Please take a look at below code.
Code:
 
$NOW='['$(date +"%Y-%d-%m %r")']'
echo $NOW
[2013-22-07 04:09:36 AM]

After 5 minutes

Code:
$echo $NOW
[2013-22-07 04:09:36 AM]

Issue here is , I am not able to figure out how to evaluate NOW varialbe at run time. It keeps displaying the same time.
I tried some combinations with expr , eval and " ` " , but none of them work.

Can you please help me here.
# 2  
Old 07-22-2013
looking at your req i suggest you using
Quote:
alias
or else it should be

Code:
vidya> v=date
vidya> echo `$v`
Mon Jul 22 12:00:44 CEST 2013
vidya> echo `$v`
Mon Jul 22 12:00:48 CEST 2013
vidya> echo `$v`
Mon Jul 22 12:00:50 CEST 2013
vidya>

This User Gave Thanks to vidyadhar85 For This Post:
# 3  
Old 07-22-2013
Code:
$ alias NOW='echo [$(date +"%Y-%d-%m %r")]'
$ NOW
[2013-22-07 3:31:05 PM]
$ NOW
[2013-22-07 3:31:07 PM]

This User Gave Thanks to anbu23 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Runtime variable extraction

Hi There, var1=value1 var2=value2 var3=value3 for (( i=1; i<4; i++ )) do temp=var$i echo "$temp" done OUTPUT var1 var2 var3 I want the output to be value1 value2 (5 Replies)
Discussion started by: jagpreetc
5 Replies

2. Shell Programming and Scripting

Evaluate Expression within awk

I want to create a conditional expression string and pass in an awk script. My script is as below... comm="\$3 == "hello"" awk -F "^T" -v command="${comm}" ' { if ( command ) { print "hye" } }' testBut the statement "if ( command )" always evaluates to true which is not... (5 Replies)
Discussion started by: Saikat123
5 Replies

3. Shell Programming and Scripting

How to evaluate a variable name on LHS of expression?

I am trying to write a simple function to select values from a database and assign them to variables. It can have any number of arguments sent into it, and I want to assign the value retrieved to a different variable name for each argument sent in. So my code looks something like this: ... (6 Replies)
Discussion started by: DJR
6 Replies

4. UNIX for Dummies Questions & Answers

How does ||: evaluate?

In BASH, how does ||: get interpreted. I know || is logical or. And I believe : evaluates to true. Can someone give a thorough explanation for this usage? Example for i in $IGGY do && skipdb=1 || : (6 Replies)
Discussion started by: glev2005
6 Replies

5. Shell Programming and Scripting

How to evaluate the value of a variable ?

How to evaluate the value of a variable ? For example: a=var $a=value !!!error happens!!! I want to evaluate var=value, how to realize it? Thanks! ---------- Post updated at 03:37 AM ---------- Previous update was at 02:22 AM ---------- I am using linux bash. a=var $a=value... (4 Replies)
Discussion started by: 915086731
4 Replies

6. Shell Programming and Scripting

Evaluate string containing shell variable names

Hello, I have this: #!/usr/bin/ksh V1=ABC str="hello 123;${V1}" eval "echo $str" i get hello 123 /script.sh ABC not found However eval works if $str variable doesn't contain a semicolumn (eg if str="hello 123~${v1}" running the eval statement above would produce (2 Replies)
Discussion started by: endorphin
2 Replies

7. Shell Programming and Scripting

generating the variable list for WHILE READ statement at runtime

Hi, I am reading the contents of a file in variables as - cat ${var_file_name} | while read COL1 COL2 COL3 COL4 COL5 COL6 COL7 COL8 COL9 COL10 COL11 The problem is ... my file can have any number of columns - 5, 10, 11 .... So i want a dynamic variable list as - cat ${var_file_name} |... (8 Replies)
Discussion started by: gopalss
8 Replies

8. Programming

How to evaluate which coding approach is best?

Let's say for example that we have two different ways was can code the exact same program to achieve the same result. What is the best way to determine which of the two methods is the best solution? Is it as simple as basing it on how long the program takes to run or is there a more... (4 Replies)
Discussion started by: jmvbxx
4 Replies

9. Shell Programming and Scripting

Evaluate the value of a variable?

I have variables: FOO="Text" BAR="FOO" I'd like to be able to evaluate the variable named as the value of $BAR. echo $FOO Text echo $BAR FOO This is what I'd like to do: echo ${$BAR} (this won't work) Text (3 Replies)
Discussion started by: Ilja
3 Replies

10. Shell Programming and Scripting

how to get variable to re-evaluate itself?

Probably a simple one. Basically I am retrieving a number from a file - setting a variable against it and then incrementing this by 1 and using this as an entry number in a log file for messages. I need the variable to re-evalute itself each time I call it so I get the latest number in the file -... (1 Reply)
Discussion started by: frustrated1
1 Replies
Login or Register to Ask a Question