* defining real time variables for a shell @ 2005-03-20 17:05 Eric Smith 2005-03-20 18:29 ` Bart Schaefer 0 siblings, 1 reply; 4+ messages in thread From: Eric Smith @ 2005-03-20 17:05 UTC (permalink / raw) To: Zsh Users Hi zshellers What would be a good way to define in a shell a variable for say currencies like I want to define $USD as 1.33 and $GBP as 1.44 for example. These values need to be updated at least daily and must be available to shells that are already open (I use screen and am lazy). I am thinking maybe to use a preexec function that parses a file with the values. Thanks! -- Eric Smith ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: defining real time variables for a shell 2005-03-20 17:05 defining real time variables for a shell Eric Smith @ 2005-03-20 18:29 ` Bart Schaefer [not found] ` <20050320190854.GC26316@fruitcom.com> 0 siblings, 1 reply; 4+ messages in thread From: Bart Schaefer @ 2005-03-20 18:29 UTC (permalink / raw) To: Zsh Users On Mar 20, 6:05pm, Eric Smith wrote: > > These values need to be updated at least daily and must be > available to shells that are already open (I use screen and am > lazy). > > I am thinking maybe to use a preexec function that parses a file > with the values. You'd want precmd, rather than preexec, I think. It depends on what you want to do with the values. Re-parsing a file before every prompt or command may be overkill; at the least, look at the zsh/sched module and consider updating the variables less frequently. (People tend to ask "How do I train a cat to dance?" when what they really want to know is "How do I entertain twelve eight-year-olds for two hours?" A dancing cat might keep kids happy, but it might not be the right or best solution.) You say perhaps parse a file. Where do the values in the file come from? The values will go into shell variables. Why? Is it because you want to export them in the environment so external commands can reference them? If not, maybe there's no need for variables at all. Or maybe $USD could be an expression that computes the number value, and when you need the number you use ${(e)USD}. Just food for thought. ^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <20050320190854.GC26316@fruitcom.com>]
[parent not found: <050320115822.ZM9627@candle.brasslantern.com>]
* Re: defining real time variables for a shell [not found] ` <050320115822.ZM9627@candle.brasslantern.com> @ 2005-03-20 20:09 ` Eric Smith - Fruitcom 2005-03-20 22:04 ` Bart Schaefer 0 siblings, 1 reply; 4+ messages in thread From: Eric Smith - Fruitcom @ 2005-03-20 20:09 UTC (permalink / raw) To: Zsh Users Thanks Bart. According to Bart Schaefer on Sun, Mar 20, 2005 at 11:58:22AM -0800: } On Mar 20, 8:08pm, Eric Smith - Fruitcom wrote: } > Subject: Re: defining real time variables for a shell } > Thanks Bart } } (Did you intentionally send this only to me, and not to the list? No big } deal, I just wondered.) Sorry, just carelessness. } > I would like to have the forex rates in vars in order to do } > my arithmatic on the command line. } } Ah, OK. In that case I think a sched command is indeed the way to go. } } > This rule in my prexec() make it easy for me to do math fast: } > elif [[ $cmd[1] == [\(\)0-9]* ]]; then } > application=calc } > ( I think you wrote that one for me :) ) Yeah, when I have a moment, I will write how I apply this command line "mailcap" to most things I do. For example entering a pdf file on one machine will launch a pdf viewer while doing the same thing on my remote server will submit that pdf to hylafax (which sends it to the fax numbers in the header section of the pdf). } Sort of; in fact, I just made reference to that thread in a zsh-workers } posting a few minutes ago. } } > so I might do something like: } > } > '(15/$GBP)+(3750/1900)' } > .... ooops - I see it is more complicated than i thought } > to have all your cake and eat it all :) } } Just get rid of the $ sign -- it's not necessary in math context unless } you're referring to something like the length of a string with $#scalar } or the number of arguments $# or a positional parameter like $3. } } '(15/GBP)+(3750/1900)' Huh? the GBP is a var, how can a bare string be interpolated. [eric@pepper ~] $ "(15/GBP)+(3750/1900)" "GBP" is undefined ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: defining real time variables for a shell 2005-03-20 20:09 ` Eric Smith - Fruitcom @ 2005-03-20 22:04 ` Bart Schaefer 0 siblings, 0 replies; 4+ messages in thread From: Bart Schaefer @ 2005-03-20 22:04 UTC (permalink / raw) To: Zsh Users On Mar 20, 9:09pm, Eric Smith - Fruitcom wrote: } } } > elif [[ $cmd[1] == [\(\)0-9]* ]]; then } } > application=calc } } > ( I think you wrote that one for me :) ) } } Yeah, when I have a moment, I will write how I apply this command line } "mailcap" to most things I do. I think you did already: zsh-users/6463 ? } } > '(15/$GBP)+(3750/1900)' } } } } Just get rid of the $ sign -- it's not necessary in math context } } } } '(15/GBP)+(3750/1900)' } } Huh? the GBP is a var, how can a bare string be interpolated. } [eric@pepper ~] $ "(15/GBP)+(3750/1900)" } "GBP" is undefined Um, what's the application "calc"? When you said "my arithmatic on the command line" I assumed you were using zsh's built-in arithmetic, in which bare strings are treated as variable references. E.g., schaefer[509] calc() { print $(( $* )) } schaefer[510] GBP=1.44 schaefer[511] calc '(15/GBP)+(3750/1900)' 11.416666666666668 ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-03-20 22:05 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2005-03-20 17:05 defining real time variables for a shell Eric Smith 2005-03-20 18:29 ` Bart Schaefer [not found] ` <20050320190854.GC26316@fruitcom.com> [not found] ` <050320115822.ZM9627@candle.brasslantern.com> 2005-03-20 20:09 ` Eric Smith - Fruitcom 2005-03-20 22:04 ` Bart Schaefer
Code repositories for project(s) associated with this public inbox https://git.vuxu.org/mirror/zsh/ This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).