English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I'm trying to figure out how to set the value of a command to a variable.

I want to set the value of 'date +%H' to a variable called 'hour'.

set hour = ________

do I need quotes around date +%H ?

Thanks for the help.

2007-10-27 09:32:19 · 3 answers · asked by Anonymous in Computers & Internet Programming & Design

3 answers

Not exactly quotes. You need execute quotes. Like this..
set hour=`date +%H`
for me thats the character on the upper left of my keyboard under the tilde ~

It depends on if you are doing it in a script, or a login file, or at the command prompt. For me to do it in bash on a debian machine at the command prompt I have to do it as
hour=`date +%H`

2007-10-27 12:20:35 · answer #1 · answered by Gandalf Parker 7 · 2 0

it depends on what the value of the variable hour is. If it is a string, you should convert the two other variables to a string and then store them in hour. else, if you just put quotes, it will only say "date + %H" rather than the actual value for the date...you see?

2007-10-27 16:42:49 · answer #2 · answered by George H 2 · 1 0

Hey, Rich, Gandalf Parker's answer is the one. In fact I think on most key boards the execute quotes ` is on tilde ~ only

2007-10-29 07:08:28 · answer #3 · answered by Anonymous · 1 0

fedest.com, questions and answers