1) Im trying to capture the output of date +%s to a variable. I tried
the following but it doesnt seem to work. Whats wrong?
TODAY= `date +%s`
2) Im trying to read a file in a variable, but cannot. Help?
Tried stuff like
DATA=´cat textfile.txt`
3) And finally, Im hoping to subtract the two, something like this
DIFF = `$TODAY - $DATA`
Thanks in advance,
Mika
Mika,
seems to be a part of an exam, but hey, that's ok!
TODAY=`date +%s` # space after =
DATA=`cat textfile.txt` # apostroph instead of backtick
DIFF=$[ $TODAY - $DATA ] # wrong expansion operator
Regards,
Jan
I don't think that would be. I wouldn't expect a teacher to ask
someone to use non-standard features such as that %s which is a
GNU thing.
> TODAY=`date +%s` # space after =
> DATA=`cat textfile.txt` # apostroph instead of backtick
> DIFF=$[ $TODAY - $DATA ] # wrong expansion operator
[...]
$[...] is bash specific, you want to use $((...)) instead which
is POSIX/UNIX.
To get the current time in number of seconds since the epoch,
you can do:
awk 'BEGIN {srand();print srand()}'
POSIX only *suggests* that this should work. And it seems to work
with every POSIX compliant awk implementation.
Also note $(...) instead of `...`. Both are POSIX, but the
$(...) one is easier to read (and more consistent, as it aligns
with the other expansion operators that all start with $).
--
Stephane
I have one more issue.
Im starting wget via shell script with a buch of parameters. Now the
problem is, that I have to use '- signs around the URL because its long
and has a bunch of parameters that othwise wont be read by wget. But
shell script wont concat my variable when using the '- marks. So, how
can I expand the variable inside the following string.
Inside the script:
wget -O feed.xml
'http://www.terkko.helsinki.fi/feednavigator/export.php?c=Researchers&c2=Helsinki&kpl=100&from=$PARAM&dc'
Executed output:
wget -O feedit.xml
http://www.terkko.helsinki.fi/feednavigator/export.php?c=Researchers&c2=Helsinki&kpl=100&from=$PARAM&dc
-Mika
Mika,
you can simply exclude the variable from the single-quote enclosed
string:
'url-start'$PARAM'url-cont'
Regards,
Jan
> Inside the script:
> wget -O feed.xml
> 'http://www.terkko.helsinki.fi/feednavigator/export.php?c=Researchers&c2=Helsinki&kpl=100&from=$PARAM&dc'
>
> Executed output:
> wget -O feedit.xml
> http://www.terkko.helsinki.fi/feednavigator/export.php?c=Researchers&c2=Helsinki&kpl=100&from=$PARAM&dc
>
>
> -Mika
>
--
Forecast, n.:
A prediction of the future, based on the past, for
which the forecaster demands payment in the present.
let DIFF=TODAY-DATA
>
> Thanks in advance,
> Mika
>
> you can simply exclude the variable from the single-quote enclosed
> string:
> 'url-start'$PARAM'url-cont'
'url-start'"$PARAM"'url-cont'
The difference will be significant as soon as PARAM contains
characters that make it a bit more interesting - such as a space
character.