Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > alt.os.linux > #59451 > unrolled thread

type of Bash variables

Started bySoviet_Mario <SovietMario@CCCP.MIR>
First post2019-10-12 18:30 +0200
Last post2019-10-13 19:28 +0000
Articles 20 on this page of 32 — 12 participants

Back to article view | Back to alt.os.linux


Contents

  type of Bash variables Soviet_Mario <SovietMario@CCCP.MIR> - 2019-10-12 18:30 +0200
    Re: type of Bash variables Chris Elvidge <chris@mshome.net> - 2019-10-12 17:45 +0100
      Re: type of Bash variables Soviet_Mario <SovietMario@CCCP.MIR> - 2019-10-12 19:41 +0200
        Re: type of Bash variables Bit Twister <BitTwister@mouse-potato.com> - 2019-10-12 12:57 -0500
          Re: type of Bash variables Soviet_Mario <SovietMario@CCCP.MIR> - 2019-10-12 20:32 +0200
            Re: type of Bash variables William Unruh <unruh@invalid.ca> - 2019-10-13 14:47 +0000
              Re: type of Bash variables "David W. Hodgins" <dwhodgins@nomail.afraid.org> - 2019-10-13 11:12 -0400
                Re: type of Bash variables Peter 'Shaggy' Haywood <phaywood@alphalink.com.au> - 2019-10-17 17:59 +1100
        Re: type of Bash variables "David W. Hodgins" <dwhodgins@nomail.afraid.org> - 2019-10-12 14:05 -0400
          Re: type of Bash variables Soviet_Mario <SovietMario@CCCP.MIR> - 2019-10-12 20:36 +0200
            Re: type of Bash variables "David W. Hodgins" <dwhodgins@nomail.afraid.org> - 2019-10-12 16:02 -0400
        Re: type of Bash variables Paul <nospam@needed.invalid> - 2019-10-12 14:26 -0400
          Re: type of Bash variables Soviet_Mario <SovietMario@CCCP.MIR> - 2019-10-12 20:43 +0200
            Re: type of Bash variables Paul <nospam@needed.invalid> - 2019-10-12 15:18 -0400
              Re: type of Bash variables Soviet_Mario <SovietMario@CCCP.MIR> - 2019-10-12 22:44 +0200
          Re: type of Bash variables Ken Hart <kwhart1@frontier.com> - 2019-10-12 18:11 -0400
            Re: type of Bash variables "Carlos E.R." <robin_listas@es.invalid> - 2019-10-13 09:16 +0200
        Re: type of Bash variables Jasen Betts <jasen@xnet.co.nz> - 2019-10-12 20:20 +0000
          Re: type of Bash variables Soviet_Mario <SovietMario@CCCP.MIR> - 2019-10-13 10:41 +0200
        Re: type of Bash variables "Carlos E.R." <robin_listas@es.invalid> - 2019-10-13 08:18 +0200
        Re: type of Bash variables Chris Elvidge <chris@mshome.net> - 2019-10-13 11:23 +0100
          Re: type of Bash variables Soviet_Mario <SovietMario@CCCP.MIR> - 2019-10-13 13:40 +0200
        Re: type of Bash variables William Unruh <unruh@invalid.ca> - 2019-10-13 14:43 +0000
      Re: type of Bash variables Soviet_Mario <SovietMario@CCCP.MIR> - 2019-10-12 19:44 +0200
    Re: type of Bash variables Bit Twister <BitTwister@mouse-potato.com> - 2019-10-12 12:06 -0500
      Re: type of Bash variables Soviet_Mario <SovietMario@CCCP.MIR> - 2019-10-12 19:48 +0200
    Re: type of Bash variables Richard Kettlewell <invalid@invalid.invalid> - 2019-10-13 08:58 +0100
      Re: type of Bash variables Soviet_Mario <SovietMario@CCCP.MIR> - 2019-10-13 10:38 +0200
    Re: type of Bash variables William Unruh <unruh@invalid.ca> - 2019-10-13 14:36 +0000
      Re: type of Bash variables Soviet_Mario <SovietMario@CCCP.MIR> - 2019-10-13 20:58 +0200
        Re: type of Bash variables gazelle@shell.xmission.com (Kenny McCormack) - 2019-10-13 19:04 +0000
        Re: type of Bash variables William Unruh <unruh@invalid.ca> - 2019-10-13 19:28 +0000

Page 1 of 2  [1] 2  Next page →


#59451 — type of Bash variables

FromSoviet_Mario <SovietMario@CCCP.MIR>
Date2019-10-12 18:30 +0200
Subjecttype of Bash variables
Message-ID<qnsv2d$o6i$1@dont-email.me>
Are Bash variables able to be assigned or have a TYPE ?
I mean, can they be assigned numbers or dates considered not 
as strings but as typed items ?

Is it there some command to inquire on such (possible) type ?

I'm asking this for reliable comparisons not depending on 
readable human formats, but using the internal binary 
representation of data

I'm getting very surprising results trying to do algebric 
operation on dates output, like string truncations and so


-- 
1) Resistere, resistere, resistere.
2) Se tutti pagano le tasse, le tasse le pagano tutti
Soviet_Mario - (aka Gatto_Vizzato)

[toc] | [next] | [standalone]


#59452

FromChris Elvidge <chris@mshome.net>
Date2019-10-12 17:45 +0100
Message-ID<qnsvvf$u80$1@dont-email.me>
In reply to#59451
On 12/10/2019 17:30, Soviet_Mario wrote:
> 
> Are Bash variables able to be assigned or have a TYPE ?
> I mean, can they be assigned numbers or dates considered not as strings 
> but as typed items ?
They can be any type.
> 
> Is it there some command to inquire on such (possible) type ?
> 
> I'm asking this for reliable comparisons not depending on readable human 
> formats, but using the internal binary representation of data
What?
> 
> I'm getting very surprising results trying to do algebric operation on 
> dates output, like string truncations and so
> 
> 
Perhaps if you gave an example or two of the surprises, we would be able 
to help further.


-- 

Chris Elvidge, England

[toc] | [prev] | [next] | [standalone]


#59456

FromSoviet_Mario <SovietMario@CCCP.MIR>
Date2019-10-12 19:41 +0200
Message-ID<qnt393$j7d$1@dont-email.me>
In reply to#59452
Il 12/10/19 18:45, Chris Elvidge ha scritto:
> On 12/10/2019 17:30, Soviet_Mario wrote:
>>
>> Are Bash variables able to be assigned or have a TYPE ?
>> I mean, can they be assigned numbers or dates considered 
>> not as strings but as typed items ?
> They can be any type.
>>
>> Is it there some command to inquire on such (possible) type ?
>>
>> I'm asking this for reliable comparisons not depending on 
>> readable human formats, but using the internal binary 
>> representation of data
> What?

I mean, when you execute DATE and it outputs the current 
date-time, it converts from the native internal format to 
human readable with the locale.
I'd like to know if it is possible to grab directly the 
internal representation (same for numbers) and not the 
output text, in order to get efficient (and RELIABLE) 
comparisons to other date-times ...

>>
>> I'm getting very surprising results trying to do algebric 
>> operation on dates output, like string truncations and so
>>
>>
> Perhaps if you gave an example or two of the surprises, we 
> would be able to help further.
> 

I mean such exhilarating things like these

gattovizzato@dhcppc0:~$ dt=$(date)
gattovizzato@dhcppc0:~$ echo $dt
sab 12 ott 2019, 18.03.07, CEST
gattovizzato@dhcppc0:~$ dt=($dt-1)
gattovizzato@dhcppc0:~$ echo $dt
sab
gattovizzato@dhcppc0:~$ dt=($dt+1)
gattovizzato@dhcppc0:~$ echo $dt
sab+1

I was trying to add "something" (month ? second ? hour ? day 
? year ?) to a date :)



> 


-- 
1) Resistere, resistere, resistere.
2) Se tutti pagano le tasse, le tasse le pagano tutti
Soviet_Mario - (aka Gatto_Vizzato)

[toc] | [prev] | [next] | [standalone]


#59460

FromBit Twister <BitTwister@mouse-potato.com>
Date2019-10-12 12:57 -0500
Message-ID<slrnqq44vv.vir.BitTwister@wb.home.test>
In reply to#59456
On Sat, 12 Oct 2019 19:41:54 +0200, Soviet_Mario wrote:
> I was trying to add "something" (month ? second ? hour ? day
> ? year ?) to a date :)

Me thinks you need to investigate the --date arguments using date.
Some examples.
  date --date="yesterday - 1 days"
 touch -t $(date --date="now + 30 seconds" +%Y%m%d%H%M.%S) some_fn
 date --date="now + -$(date +%s)"
 date --date="4 days ago"
 date --date="now + -4 days"
 date --date="last month" +%D
 date --date="1 month ago"
 date --date="30 days ago"
 date --date="$(date +%Y-%m-15) -1 month" +'Last month was %B!'
 date --date="now + 30 minutes" '+%a %u %d %b %H %M'

[toc] | [prev] | [next] | [standalone]


#59463

FromSoviet_Mario <SovietMario@CCCP.MIR>
Date2019-10-12 20:32 +0200
Message-ID<qnt68d$5da$1@dont-email.me>
In reply to#59460
Il 12/10/19 19:57, Bit Twister ha scritto:
> On Sat, 12 Oct 2019 19:41:54 +0200, Soviet_Mario wrote:
>> I was trying to add "something" (month ? second ? hour ? day
>> ? year ?) to a date :)
> 
> Me thinks you need to investigate the --date arguments using date.

well ... actually I had just tried
I never really tried but, should I, it was an experience 
like assuming LSD

not date in particular. That and the reading of the bash 
guide suggested.
Really a trip like "altered states" (a movie from old 1980)

never seen before a language so confusing as to what is a 
value and what a reference
<goggling eyes>

> Some examples.
>    date --date="yesterday - 1 days"
>   touch -t $(date --date="now + 30 seconds" +%Y%m%d%H%M.%S) some_fn
>   date --date="now + -$(date +%s)"
>   date --date="4 days ago"
>   date --date="now + -4 days"
>   date --date="last month" +%D
>   date --date="1 month ago"
>   date --date="30 days ago"
>   date --date="$(date +%Y-%m-15) -1 month" +'Last month was %B!'
>   date --date="now + 30 minutes" '+%a %u %d %b %H %M'
> 


-- 
1) Resistere, resistere, resistere.
2) Se tutti pagano le tasse, le tasse le pagano tutti
Soviet_Mario - (aka Gatto_Vizzato)

[toc] | [prev] | [next] | [standalone]


#59507

FromWilliam Unruh <unruh@invalid.ca>
Date2019-10-13 14:47 +0000
Message-ID<qnvde6$ntc$4@dont-email.me>
In reply to#59463
On 2019-10-12, Soviet_Mario <SovietMario@CCCP.MIR> wrote:
> Il 12/10/19 19:57, Bit Twister ha scritto:
>> On Sat, 12 Oct 2019 19:41:54 +0200, Soviet_Mario wrote:
>>> I was trying to add "something" (month ? second ? hour ? day
>>> ? year ?) to a date :)
>> 
>> Me thinks you need to investigate the --date arguments using date.
>
> well ... actually I had just tried
> I never really tried but, should I, it was an experience 
> like assuming LSD
>
> not date in particular. That and the reading of the bash 
> guide suggested.
> Really a trip like "altered states" (a movie from old 1980)
>
> never seen before a language so confusing as to what is a 
> value and what a reference

ALL bash variables are strings. 
man bash will tell you how to manipulate those to do arithmetic. Or as
Bit ways, you can use the output of the "date" command to to accomplish
what you want. 

><goggling eyes>
>
>> Some examples.
>>    date --date="yesterday - 1 days"
>>   touch -t $(date --date="now + 30 seconds" +%Y%m%d%H%M.%S) some_fn
>>   date --date="now + -$(date +%s)"
>>   date --date="4 days ago"
>>   date --date="now + -4 days"
>>   date --date="last month" +%D
>>   date --date="1 month ago"
>>   date --date="30 days ago"
>>   date --date="$(date +%Y-%m-15) -1 month" +'Last month was %B!'
>>   date --date="now + 30 minutes" '+%a %u %d %b %H %M'
>> 
>
>

[toc] | [prev] | [next] | [standalone]


#59509

From"David W. Hodgins" <dwhodgins@nomail.afraid.org>
Date2019-10-13 11:12 -0400
Message-ID<op.z9ltu1hva3w0dxdave@hodgins.homeip.net>
In reply to#59507
On Sun, 13 Oct 2019 10:47:34 -0400, William Unruh <unruh@invalid.ca> wrote:

> ALL bash variables are strings.

False, as previously explained. Otherwise explain the following ...
[dave@x3 ~]$ cat bin/declarei
#!/bin/bash
declare -i number=42
echo $number
number='somestring'
echo $number
[dave@x3 ~]$ bin/declarei
42
0

Regards, Dave Hodgins

-- 
Change dwhodgins@nomail.afraid.org to davidwhodgins@teksavvy.com for
email replies.

[toc] | [prev] | [next] | [standalone]


#59812

FromPeter 'Shaggy' Haywood <phaywood@alphalink.com.au>
Date2019-10-17 17:59 +1100
Message-ID<83gl7g-tg1.ln1@aretha.foo>
In reply to#59509
Groovy hepcat David W. Hodgins was jivin' in alt.os.linux on Mon, 14 Oct
2019 02:12 am. It's a cool scene! Dig it.

> On Sun, 13 Oct 2019 10:47:34 -0400, William Unruh <unruh@invalid.ca>
> wrote:
> 
>> ALL bash variables are strings.
> 
> False, as previously explained. Otherwise explain the following ...
> [dave@x3 ~]$ cat bin/declarei
> #!/bin/bash
> declare -i number=42
> echo $number
> number='somestring'
> echo $number
> [dave@x3 ~]$ bin/declarei
> 42
> 0

  Indeed, there are also indexed arrays, associative arrays and namerefs
(references to other variables).

-- 


----- Dig the NEW and IMPROVED news sig!! -----


-------------- Shaggy was here! ---------------
              Ain't I'm a dawg!!

[toc] | [prev] | [next] | [standalone]


#59461

From"David W. Hodgins" <dwhodgins@nomail.afraid.org>
Date2019-10-12 14:05 -0400
Message-ID<op.z9j663dia3w0dxdave@hodgins.homeip.net>
In reply to#59456
On Sat, 12 Oct 2019 13:41:54 -0400, Soviet_Mario <SovietMario@cccp.mir> wrote:

> I mean, when you execute DATE and it outputs the current
> date-time, it converts from the native internal format to
> human readable with the locale.
> I'd like to know if it is possible to grab directly the
> internal representation (same for numbers) and not the
> output text, in order to get efficient (and RELIABLE)
> comparisons to other date-times ...

See man date. For example, seconds since 1970-01-01 00:00:00 UTC
(i.e epoch) ...
$ date +%s
1570902695

>>> I'm getting very surprising results trying to do algebric
>>> operation on dates output, like string truncations and so

Normally bash variables are not typed, allowing the variable's type
to be controlled by the type of value it's set to.

If the variable's type has been declared, and an assignment to a value
not consistent with that type is attempted, the assignment will not
change the variable's content. For example ...
$ declare -i asdf
$ asdf="x"
$ echo $asdf
0

> I was trying to add "something" (month ? second ? hour ? day
> ? year ?) to a date :)

Convert the date to seconds since 1970 started, do the arithmetic, then
convert to a date format you want to display. The date command can be
used to convert between formats, including seconds since epoch.

Regards, Dave Hodgins

-- 
Change dwhodgins@nomail.afraid.org to davidwhodgins@teksavvy.com for
email replies.

[toc] | [prev] | [next] | [standalone]


#59464

FromSoviet_Mario <SovietMario@CCCP.MIR>
Date2019-10-12 20:36 +0200
Message-ID<qnt6fo$5da$2@dont-email.me>
In reply to#59461
Il 12/10/19 20:05, David W. Hodgins ha scritto:
> On Sat, 12 Oct 2019 13:41:54 -0400, Soviet_Mario 
> <SovietMario@cccp.mir> wrote:
> 
>> I mean, when you execute DATE and it outputs the current
>> date-time, it converts from the native internal format to
>> human readable with the locale.
>> I'd like to know if it is possible to grab directly the
>> internal representation (same for numbers) and not the
>> output text, in order to get efficient (and RELIABLE)
>> comparisons to other date-times ...
> 
> See man date. For example, seconds since 1970-01-01 00:00:00 
> UTC
> (i.e epoch) ...
> $ date +%s
> 1570902695
> 
>>>> I'm getting very surprising results trying to do algebric
>>>> operation on dates output, like string truncations and so
> 
> Normally bash variables are not typed, allowing the 
> variable's type
> to be controlled by the type of value it's set to.
> 
> If the variable's type has been declared, and an assignment 
> to a value
> not consistent with that type is attempted, the assignment 
> will not
> change the variable's content. For example ...
> $ declare -i asdf

uh ! DECLARE !
well I must have missed this construct at all :(

> $ asdf="x"
> $ echo $asdf
> 0

when is LET mandatory and when not ?

> 
>> I was trying to add "something" (month ? second ? hour ? day
>> ? year ?) to a date :)
> 
> Convert the date to seconds since 1970 started, do the 
> arithmetic, then
> convert to a date format you want to display. The date 
> command can be
> used to convert between formats, including seconds since epoch.

i was trying to do so, but I failed (don't remember why)
Yes the absolute number of seconds is equivalent to what I 
was trying

> 
> Regards, Dave Hodgins
> 


-- 
1) Resistere, resistere, resistere.
2) Se tutti pagano le tasse, le tasse le pagano tutti
Soviet_Mario - (aka Gatto_Vizzato)

[toc] | [prev] | [next] | [standalone]


#59468

From"David W. Hodgins" <dwhodgins@nomail.afraid.org>
Date2019-10-12 16:02 -0400
Message-ID<op.z9kcm8e0a3w0dxdave@hodgins.homeip.net>
In reply to#59464
On Sat, 12 Oct 2019 14:36:40 -0400, Soviet_Mario <SovietMario@cccp.mir> wrote:

> when is LET mandatory and when not ?

It's never mandatory, as one of the other arithmetic methods, the expr command or double parentheses, can be used in place of the let bash
builtin command.
http://www.tldp.org/LDP/abs/html/arithexp.html

It's "let", not "LET", as bash, like most things in linux, is case
sensitive.

Regards, Dave Hodgins

-- 
Change dwhodgins@nomail.afraid.org to davidwhodgins@teksavvy.com for
email replies.

[toc] | [prev] | [next] | [standalone]


#59462

FromPaul <nospam@needed.invalid>
Date2019-10-12 14:26 -0400
Message-ID<qnt5sh$350$1@dont-email.me>
In reply to#59456
Soviet_Mario wrote:
> Il 12/10/19 18:45, Chris Elvidge ha scritto:
>> On 12/10/2019 17:30, Soviet_Mario wrote:
>>>
>>> Are Bash variables able to be assigned or have a TYPE ?
>>> I mean, can they be assigned numbers or dates considered not as 
>>> strings but as typed items ?
>> They can be any type.
>>>
>>> Is it there some command to inquire on such (possible) type ?
>>>
>>> I'm asking this for reliable comparisons not depending on readable 
>>> human formats, but using the internal binary representation of data
>> What?
> 
> I mean, when you execute DATE and it outputs the current date-time, it 
> converts from the native internal format to human readable with the locale.
> I'd like to know if it is possible to grab directly the internal 
> representation (same for numbers) and not the output text, in order to 
> get efficient (and RELIABLE) comparisons to other date-times ...
> 
>>>
>>> I'm getting very surprising results trying to do algebric operation 
>>> on dates output, like string truncations and so
>>>
>>>
>> Perhaps if you gave an example or two of the surprises, we would be 
>> able to help further.
>>
> 
> I mean such exhilarating things like these
> 
> gattovizzato@dhcppc0:~$ dt=$(date)
> gattovizzato@dhcppc0:~$ echo $dt
> sab 12 ott 2019, 18.03.07, CEST
> gattovizzato@dhcppc0:~$ dt=($dt-1)
> gattovizzato@dhcppc0:~$ echo $dt
> sab
> gattovizzato@dhcppc0:~$ dt=($dt+1)
> gattovizzato@dhcppc0:~$ echo $dt
> sab+1
> 
> I was trying to add "something" (month ? second ? hour ? day ? year ?) 
> to a date :)

This isn't shell, but you could try to prepare
an executable for the job.

https://linux.die.net/man/3/clock_gettime

What I did, is used these calls I use in Windows

     QueryPerformanceCounter((LARGE_INTEGER *) &time1);
     QueryPerformanceFrequency((LARGE_INTEGER *)&freq);

and ask Google for the equivalent in Linux, and that
was the answer I got, to use clock_gettime. Then,
by specifying the correct option (say CLOCK_REALTIME),
you might get something similar to shell DATE. With
some luck, the clock has a resolution of around 100ns
or so.

You don't want to be doing "maths" on the string
that DATE returns. Think of all the programmatic
"holes" you can fall into, such as the time interval
near the "time change" (daylight savings time). You
want to work with a single monotonic number used by
the system, add a manifest constant to that value,
*then* call a conversion routine to make an actual
string from it. Try to get as much value from all
of that time code running on your system, as possible.

Working with "time" is always dangerous as a programmer,
no matter what level you work at. There are a million
things to know, and many many traps for the unwary
programmer. And on the USENET, there are a few
"Time Lords" who will tear apart and make fun
of your code :-)

    Paul

[toc] | [prev] | [next] | [standalone]


#59465

FromSoviet_Mario <SovietMario@CCCP.MIR>
Date2019-10-12 20:43 +0200
Message-ID<qnt6rm$8q8$1@dont-email.me>
In reply to#59462
Il 12/10/19 20:26, Paul ha scritto:
> Soviet_Mario wrote:
>> Il 12/10/19 18:45, Chris Elvidge ha scritto:
>>> On 12/10/2019 17:30, Soviet_Mario wrote:
>>>>
>>>> Are Bash variables able to be assigned or have a TYPE ?
>>>> I mean, can they be assigned numbers or dates considered 
>>>> not as strings but as typed items ?
>>> They can be any type.
>>>>
>>>> Is it there some command to inquire on such (possible) 
>>>> type ?
>>>>
>>>> I'm asking this for reliable comparisons not depending 
>>>> on readable human formats, but using the internal binary 
>>>> representation of data
>>> What?
>>
>> I mean, when you execute DATE and it outputs the current 
>> date-time, it converts from the native internal format to 
>> human readable with the locale.
>> I'd like to know if it is possible to grab directly the 
>> internal representation (same for numbers) and not the 
>> output text, in order to get efficient (and RELIABLE) 
>> comparisons to other date-times ...
>>
>>>>
>>>> I'm getting very surprising results trying to do 
>>>> algebric operation on dates output, like string 
>>>> truncations and so
>>>>
>>>>
>>> Perhaps if you gave an example or two of the surprises, 
>>> we would be able to help further.
>>>
>>
>> I mean such exhilarating things like these
>>
>> gattovizzato@dhcppc0:~$ dt=$(date)
>> gattovizzato@dhcppc0:~$ echo $dt
>> sab 12 ott 2019, 18.03.07, CEST
>> gattovizzato@dhcppc0:~$ dt=($dt-1)
>> gattovizzato@dhcppc0:~$ echo $dt
>> sab
>> gattovizzato@dhcppc0:~$ dt=($dt+1)
>> gattovizzato@dhcppc0:~$ echo $dt
>> sab+1
>>
>> I was trying to add "something" (month ? second ? hour ? 
>> day ? year ?) to a date :)
> 
> This isn't shell, but you could try to prepare
> an executable for the job.
> 
> https://linux.die.net/man/3/clock_gettime
> 
> What I did, is used these calls I use in Windows
> 
>      QueryPerformanceCounter((LARGE_INTEGER *) &time1);
>      QueryPerformanceFrequency((LARGE_INTEGER *)&freq);
> 
> and ask Google for the equivalent in Linux, and that
> was the answer I got, to use clock_gettime. Then,
> by specifying the correct option (say CLOCK_REALTIME),
> you might get something similar to shell DATE. With
> some luck, the clock has a resolution of around 100ns
> or so.
> 
> You don't want to be doing "maths" on the string
> that DATE returns. Think of all the programmatic
> "holes" you can fall into, such as the time interval
> near the "time change" (daylight savings time). You
> want to work with a single monotonic number used by
> the system, add a manifest constant to that value,
> *then* call a conversion routine to make an actual
> string from it. Try to get as much value from all
> of that time code running on your system, as possible.
> 
> Working with "time" is always dangerous as a programmer,
> no matter what level you work at. There are a million
> things to know, and many many traps for the unwary
> programmer. And on the USENET, there are a few
> "Time Lords" who will tear apart and make fun
> of your code :-)
> 
>     Paul


hi paul, I was tinkering with bash as I'm getting stuck with 
gambas shell function (it simply hangs and the shelled task 
sleeps forever, even if use a flag to wait for its 
completion, then it starts paradoxically only when I 
manually KILL the parent process from task list ... and 
surprisingly it runs till completion).

Normally I was doing dates comparison from within gambas 
ifself, as it replicate stat function and "STATS" files, 
then simple memberwise comparison of fields (atime, mtime, 
etc) works well, hiding all human datetime representation => 
STATS uses internal representation

then I had the very sick insane idea to try sth with bash. 
And it's like assuming an overdose of LSD :)

Im becoming convinced bash was created by sb able to love 
even PERL :) :\ :o

-- 
1) Resistere, resistere, resistere.
2) Se tutti pagano le tasse, le tasse le pagano tutti
Soviet_Mario - (aka Gatto_Vizzato)

[toc] | [prev] | [next] | [standalone]


#59467

FromPaul <nospam@needed.invalid>
Date2019-10-12 15:18 -0400
Message-ID<qnt8ua$ke3$1@dont-email.me>
In reply to#59465
Soviet_Mario wrote:

> hi paul, I was tinkering with bash as I'm getting stuck with gambas 
> shell function (it simply hangs and the shelled task sleeps forever, 
> even if use a flag to wait for its completion, then it starts 
> paradoxically only when I manually KILL the parent process from task 
> list ... and surprisingly it runs till completion).

Doesn't "date" wait for keyboard input for some
of its operation modes ?

That could be why gambas shell function hangs, as
it's waiting for "date" to come back, and date will
only come back after the interactive strings are
entered from the keyboard.

Be careful what operations you select for "date"
to do, so that date does not try to collect
keyboard input.

    Paul

[toc] | [prev] | [next] | [standalone]


#59470

FromSoviet_Mario <SovietMario@CCCP.MIR>
Date2019-10-12 22:44 +0200
Message-ID<qntdv3$i9v$1@dont-email.me>
In reply to#59467
Il 12/10/19 21:18, Paul ha scritto:
> Soviet_Mario wrote:
> 
>> hi paul, I was tinkering with bash as I'm getting stuck 
>> with gambas shell function (it simply hangs and the 
>> shelled task sleeps forever, even if use a flag to wait 
>> for its completion, then it starts paradoxically only when 
>> I manually KILL the parent process from task list ... and 
>> surprisingly it runs till completion).
> 
> Doesn't "date" wait for keyboard input for some
> of its operation modes ?

no the shelled command was "sudo find etc etc etc"
and, among other things, did not put out any popup to ask 
for password.
But the cmq would sleep even without the SUDO.
Dunno why :\

> 
> That could be why gambas shell function hangs, as
> it's waiting for "date" to come back, and date will
> only come back after the interactive strings are
> entered from the keyboard.

yes I had thoght so for SUDO prefix ... but it got stuck 
even without it.

The rest of the program works well : if I execute the 
command in a terminal and then I feed the file produced in 
the program, it makes every further filtering I was working on.
But I can't get to have SHELL work fine :\

> 
> Be careful what operations you select for "date"
> to do, so that date does not try to collect
> keyboard input.

in shell I was generating unfiltered huge file listings 
(that's why I opened also the other 3D on a editor to munch 
500 MB-1 GB sized text files .... later I provided an 
embedded viewer, no more problems. It scans a 500 MB text in 
2 sec (32 KB read chunks) and in one shot stores every 
occurrence of search terms, then navigate is easy.
I did not strictly need an editor, a viewer was enoogh, as 
filtering and tuning options was to be done programmatically 
and never manually

I am untidy, I work upon too many things at a time and 
seldom get sth work :\




> 
>     Paul


-- 
1) Resistere, resistere, resistere.
2) Se tutti pagano le tasse, le tasse le pagano tutti
Soviet_Mario - (aka Gatto_Vizzato)

[toc] | [prev] | [next] | [standalone]


#59473

FromKen Hart <kwhart1@frontier.com>
Date2019-10-12 18:11 -0400
Message-ID<qntj2v$1bor$1@gioia.aioe.org>
In reply to#59462
On 10/12/19 2:26 PM, Paul wrote:
> Soviet_Mario wrote:
>> Il 12/10/19 18:45, Chris Elvidge ha scritto:
>>> On 12/10/2019 17:30, Soviet_Mario wrote:
>>>>
>>>> Are Bash variables able to be assigned or have a TYPE ?
>>>> I mean, can they be assigned numbers or dates considered not as 
>>>> strings but as typed items ?
>>> They can be any type.
>>>>
>>>> Is it there some command to inquire on such (possible) type ?
>>>>
>>>> I'm asking this for reliable comparisons not depending on readable 
>>>> human formats, but using the internal binary representation of data
>>> What?
>>
>> I mean, when you execute DATE and it outputs the current date-time, it 
>> converts from the native internal format to human readable with the 
>> locale.
>> I'd like to know if it is possible to grab directly the internal 
>> representation (same for numbers) and not the output text, in order to 
>> get efficient (and RELIABLE) comparisons to other date-times ...
>>
>>>>
>>>> I'm getting very surprising results trying to do algebric operation 
>>>> on dates output, like string truncations and so
>>>>
>>>>
>>> Perhaps if you gave an example or two of the surprises, we would be 
>>> able to help further.
>>>
>>
>> I mean such exhilarating things like these
>>
>> gattovizzato@dhcppc0:~$ dt=$(date)
>> gattovizzato@dhcppc0:~$ echo $dt
>> sab 12 ott 2019, 18.03.07, CEST
>> gattovizzato@dhcppc0:~$ dt=($dt-1)
>> gattovizzato@dhcppc0:~$ echo $dt
>> sab
>> gattovizzato@dhcppc0:~$ dt=($dt+1)
>> gattovizzato@dhcppc0:~$ echo $dt
>> sab+1
>>
>> I was trying to add "something" (month ? second ? hour ? day ? year ?) 
>> to a date :)
> 
> This isn't shell, but you could try to prepare
> an executable for the job.
> 
> https://linux.die.net/man/3/clock_gettime
> 
> What I did, is used these calls I use in Windows
> 
>      QueryPerformanceCounter((LARGE_INTEGER *) &time1);
>      QueryPerformanceFrequency((LARGE_INTEGER *)&freq);
> 
> and ask Google for the equivalent in Linux, and that
> was the answer I got, to use clock_gettime. Then,
> by specifying the correct option (say CLOCK_REALTIME),
> you might get something similar to shell DATE. With
> some luck, the clock has a resolution of around 100ns
> or so.
> 
> You don't want to be doing "maths" on the string
> that DATE returns. Think of all the programmatic
> "holes" you can fall into, such as the time interval
> near the "time change" (daylight savings time). You
> want to work with a single monotonic number used by
> the system, add a manifest constant to that value,
> *then* call a conversion routine to make an actual
> string from it. Try to get as much value from all
> of that time code running on your system, as possible.
> 
> Working with "time" is always dangerous as a programmer,
> no matter what level you work at. There are a million
> things to know, and many many traps for the unwary
> programmer. And on the USENET, there are a few
> "Time Lords" who will tear apart and make fun
> of your code :-)
> 
>     Paul

For a comedic look at the problem of doing "maths" on time, check out a 
youtube video by Tom Scott: The problem with times and timezones.
https://www.youtube.com/watch?v=-5wpm-gesOY


-- 
Ken Hart
kwhart1@frontier.com

[toc] | [prev] | [next] | [standalone]


#59487

From"Carlos E.R." <robin_listas@es.invalid>
Date2019-10-13 09:16 +0200
Message-ID<qiva7g-4kk.ln1@Telcontar.valinor>
In reply to#59473
On 13/10/2019 00.11, Ken Hart wrote:
> On 10/12/19 2:26 PM, Paul wrote:
>> Soviet_Mario wrote:
>>> Il 12/10/19 18:45, Chris Elvidge ha scritto:
>>>> On 12/10/2019 17:30, Soviet_Mario wrote:


> 
> For a comedic look at the problem of doing "maths" on time, check out a
> youtube video by Tom Scott: The problem with times and timezones.
> https://www.youtube.com/watch?v=-5wpm-gesOY

:-D


-- 
Cheers, Carlos.

[toc] | [prev] | [next] | [standalone]


#59469

FromJasen Betts <jasen@xnet.co.nz>
Date2019-10-12 20:20 +0000
Message-ID<qntcie$9gj$2@gonzo.revmaps.no-ip.org>
In reply to#59456
On 2019-10-12, Soviet_Mario <SovietMario@CCCP.MIR> wrote:
> Il 12/10/19 18:45, Chris Elvidge ha scritto:
>> On 12/10/2019 17:30, Soviet_Mario wrote:
>>>
>>> Are Bash variables able to be assigned or have a TYPE ?
>>> I mean, can they be assigned numbers or dates considered 
>>> not as strings but as typed items ?
>> They can be any type.
>>>
>>> Is it there some command to inquire on such (possible) type ?
>>>
>>> I'm asking this for reliable comparisons not depending on 
>>> readable human formats, but using the internal binary 
>>> representation of data
>> What?
>
> I mean, when you execute DATE and it outputs the current 
> date-time, it converts from the native internal format to 
> human readable with the locale.
> I'd like to know if it is possible to grab directly the 
> internal representation (same for numbers) and not the 
> output text, in order to get efficient (and RELIABLE) 
> comparisons to other date-times ...

 epoch=$(date "+%s")


> I mean such exhilarating things like these
>
> gattovizzato@dhcppc0:~$ dt=$(date)
> gattovizzato@dhcppc0:~$ echo $dt
> sab 12 ott 2019, 18.03.07, CEST
> gattovizzato@dhcppc0:~$ dt=($dt-1)
> gattovizzato@dhcppc0:~$ echo $dt
> sab
> gattovizzato@dhcppc0:~$ dt=($dt+1)
> gattovizzato@dhcppc0:~$ echo $dt
> sab+1

an interesting mis-use of arrays there: ( ) doesn't mean what you seem
to think it might.

> I was trying to add "something" (month ? second ? hour ? day 
> ? year ?) to a date :)

bash doesn't understand dates, but date does;

 date -d 'next month'

 date -d "@$epoch 2 days ago"

-- 
  When I tried casting out nines I made a hash of it.

[toc] | [prev] | [next] | [standalone]


#59490

FromSoviet_Mario <SovietMario@CCCP.MIR>
Date2019-10-13 10:41 +0200
Message-ID<qnunv7$grq$2@dont-email.me>
In reply to#59469
Il 12/10/19 22:20, Jasen Betts ha scritto:
> On 2019-10-12, Soviet_Mario <SovietMario@CCCP.MIR> wrote:
>> Il 12/10/19 18:45, Chris Elvidge ha scritto:
>>> On 12/10/2019 17:30, Soviet_Mario wrote:
>>>>
>>>> Are Bash variables able to be assigned or have a TYPE ?
>>>> I mean, can they be assigned numbers or dates considered
>>>> not as strings but as typed items ?
>>> They can be any type.
>>>>
>>>> Is it there some command to inquire on such (possible) type ?
>>>>
>>>> I'm asking this for reliable comparisons not depending on
>>>> readable human formats, but using the internal binary
>>>> representation of data
>>> What?
>>
>> I mean, when you execute DATE and it outputs the current
>> date-time, it converts from the native internal format to
>> human readable with the locale.
>> I'd like to know if it is possible to grab directly the
>> internal representation (same for numbers) and not the
>> output text, in order to get efficient (and RELIABLE)
>> comparisons to other date-times ...
> 
>   epoch=$(date "+%s")
> 
> 
>> I mean such exhilarating things like these
>>
>> gattovizzato@dhcppc0:~$ dt=$(date)
>> gattovizzato@dhcppc0:~$ echo $dt
>> sab 12 ott 2019, 18.03.07, CEST
>> gattovizzato@dhcppc0:~$ dt=($dt-1)
>> gattovizzato@dhcppc0:~$ echo $dt
>> sab
>> gattovizzato@dhcppc0:~$ dt=($dt+1)
>> gattovizzato@dhcppc0:~$ echo $dt
>> sab+1
> 
> an interesting mis-use of arrays there: ( ) doesn't mean what you seem
> to think it might.
> 

well I still have not revised the declaration of arrays, but 
I am also completely confused about quoting with "" or '' 
and the use of different kinds of parentheses

>> I was trying to add "something" (month ? second ? hour ? day
>> ? year ?) to a date :)
> 
> bash doesn't understand dates, but date does;
> 
>   date -d 'next month'
> 
>   date -d "@$epoch 2 days ago"
> 

this "+%s" seems perfect anyway, especially combined with 
the input character @ used later
Tnx


-- 
1) Resistere, resistere, resistere.
2) Se tutti pagano le tasse, le tasse le pagano tutti
Soviet_Mario - (aka Gatto_Vizzato)

[toc] | [prev] | [next] | [standalone]


#59485

From"Carlos E.R." <robin_listas@es.invalid>
Date2019-10-13 08:18 +0200
Message-ID<j6sa7g-euh.ln1@Telcontar.valinor>
In reply to#59456
On 12/10/2019 19.41, Soviet_Mario wrote:
> Il 12/10/19 18:45, Chris Elvidge ha scritto:
>> On 12/10/2019 17:30, Soviet_Mario wrote:
>>>
>>> Are Bash variables able to be assigned or have a TYPE ?
>>> I mean, can they be assigned numbers or dates considered not as
>>> strings but as typed items ?
>> They can be any type.
>>>
>>> Is it there some command to inquire on such (possible) type ?
>>>
>>> I'm asking this for reliable comparisons not depending on readable
>>> human formats, but using the internal binary representation of data
>> What?
> 
> I mean, when you execute DATE and it outputs the current date-time, it
> converts from the native internal format to human readable with the locale.
> I'd like to know if it is possible to grab directly the internal
> representation (same for numbers) and not the output text, in order to
> get efficient (and RELIABLE) comparisons to other date-times ...

It is always text. It may be a number, but a number represented as text,
not the binary number.

When using the date command, you can output in text the long number that
is the internal date representation (seconds since the epoch).

> I was trying to add "something" (month ? second ? hour ? day ? year ?)
> to a date :)

Then you have to use printfmt option, see "pinfo date" or "info date".
NOT "man date".

-- 
Cheers, Carlos.

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | alt.os.linux


csiph-web