Re: [gentoo-user] bash date puzzle

2011-11-14 Thread Neil Bothwick
On Mon, 14 Nov 2011 02:06:04 -0500, Philip Webb wrote:

 To convert a UNIX date to a human-readable version the command is :
 
   556: ~ date -d @1321251520
   Mon Nov 14 01:18:40 EST 2011
   
 I would like to create a Bash alias or function to do this,
 but can't get the Bash syntax right: it keeps telling me
 date: the argument `1321251520' lacks a leading `+';
 when using an option to specify date(s), any non-option
 argument must be a format string beginning with `+'
 Try `date --help' for more information.

It is difficult to say what is wrong with your alias as you haven't shown
it, but my guess is that is is introducing a space between the @ and the
timestamp, which gives exactly the error you get.


-- 
Neil Bothwick

When companies ship Styrofoam, what do they pack it in?


signature.asc
Description: PGP signature


Re: [gentoo-user] bash date puzzle

2011-11-14 Thread Paul Colquhoun
On Mon, 14 Nov 2011 06:13:34 AM Philip Webb wrote:
 14 Neil Bothwick wrote:
  On Mon, 14 Nov 2011 02:06:04 -0500, Philip Webb wrote:
  To convert a UNIX date to a human-readable version the command is :
556: ~ date -d @1321251520
Mon Nov 14 01:18:40 EST 2011
  
  I would like to create a Bash alias or function to do this,
  but can't get the Bash syntax right: it keeps telling me
  date: the argument `1321251520' lacks a leading `+';
  
  It is difficult to say what is wrong with your alias
  as you haven't shown it
 
   alias th='date -d @$1'
 
 was the first try, then adding '+' /or '\' to escape '+' or '@'.
 I also tried a function along similar lines.
 
  but my guess is that is is introducing a space
  between @ and the timestamp, which gives exactly the error you get.
 
 No, no spaces.


Aliases don't take argument, you need a function for that.

Turning on shell debugging shows what is happening

$ set -x
+ set -x

$ alias th='date -d @$1'
+ alias 'th=date -d @$1'

$ th 1321251520
+ date -d @ 1321251520
date: the argument `1321251520' lacks a leading `+';
when using an option to specify date(s), any non-option
argument must be a format string beginning with `+'
Try `date --help' for more information.


  Now set a value to $1 and see what happenes...


$ set -- 'Ha Ha'
+ set -- 'Ha Ha'

$ th 1321251520
+ date -d @Ha Ha 1321251520
date: extra operand `1321251520'
Try `date --help' for more information.

$ set +x


All the 'alias' process does is simple text substitution.


-- 
Reverend Paul Colquhoun, ULC.http://andor.dropbear.id.au/~paulcol
 Before you criticize someone, you should walk a mile in their shoes.
Then, when you do, you'll be a mile away, and you'll have their shoes.




Re: [gentoo-user] bash date puzzle

2011-11-14 Thread Willie Wong
On Mon, Nov 14, 2011 at 06:13:34AM -0500, Philip Webb wrote:
   alias th='date -d @$1'
 
 was the first try, then adding '+' /or '\' to escape '+' or '@'.
 I also tried a function along similar lines.
 

That is not how you use alias. 

What you want is to use a function. Replace the alias line by

function th { date -d @$1; }

in your bashrc you'l probably be ok. 

W
-- 
Willie W. Wong ww...@math.princeton.edu
Data aequatione quotcunque fluentes quantitae involvente fluxiones invenire 
 et vice versa   ~~~  I. Newton



Re: [gentoo-user] bash date puzzle

2011-11-14 Thread Philip Webb
14 Neil Bothwick wrote:
 On Mon, 14 Nov 2011 02:06:04 -0500, Philip Webb wrote:
 To convert a UNIX date to a human-readable version the command is :
   556: ~ date -d @1321251520
   Mon Nov 14 01:18:40 EST 2011
 I would like to create a Bash alias or function to do this,
 but can't get the Bash syntax right: it keeps telling me
 date: the argument `1321251520' lacks a leading `+';
 It is difficult to say what is wrong with your alias
 as you haven't shown it

  alias th='date -d @$1'

was the first try, then adding '+' /or '\' to escape '+' or '@'.
I also tried a function along similar lines.

 but my guess is that is is introducing a space
 between @ and the timestamp, which gives exactly the error you get.

No, no spaces.

-- 
,,
SUPPORT ___//___,   Philip Webb
ELECTRIC   /] [] [] [] [] []|   Cities Centre, University of Toronto
TRANSIT`-O--O---'   purslowatchassdotutorontodotca




Re: [gentoo-user] bash date puzzle

2011-11-14 Thread Neil Bothwick
On Mon, 14 Nov 2011 06:13:34 -0500, Philip Webb wrote:

  It is difficult to say what is wrong with your alias
  as you haven't shown it  
 
   alias th='date -d @$1'
 
 was the first try, then adding '+' /or '\' to escape '+' or '@'.
 I also tried a function along similar lines.
 
  but my guess is that is is introducing a space
  between @ and the timestamp, which gives exactly the error you get.  
 
 No, no spaces.

You invoke it as 'alias argument', so there is a space between the alias
and the argument and this space is included when the alias is expanded.
Otherwise aliases like ll='ls -l' would not work as 'll /mnt' would be
expanded to 'ls -l/mnt'.


-- 
Neil Bothwick

My brain's in gear, neutral's a gear ain't it?


signature.asc
Description: PGP signature


Re: [gentoo-user] bash date puzzle

2011-11-14 Thread Philip Webb
14 Willie Wong wrote:
 On Mon, Nov 14, 2011 at 06:13:34AM -0500, Philip Webb wrote:
   alias th='date -d @$1'
 That is not how you use alias. 
 What you want is to use a function. Replace the alias line by
   function th { date -d @$1; }
 in your bashrc you'l probably be ok. 

That's what I thought I tried, but evidently not:

  function th { date -d @$1 ; }

does indeed work (with a space before ';').

Thanks for the various replies.

-- 
,,
SUPPORT ___//___,   Philip Webb
ELECTRIC   /] [] [] [] [] []|   Cities Centre, University of Toronto
TRANSIT`-O--O---'   purslowatchassdotutorontodotca




Re: [gentoo-user] bash date puzzle

2011-11-14 Thread Stroller

On 14 November 2011, at 07:06, Philip Webb wrote:

 To convert a UNIX date to a human-readable version the command is :
 
  556: ~ date -d @1321251520
  Mon Nov 14 01:18:40 EST 2011
 
 I would like to create a Bash alias or function to do this,
 but can't get the Bash syntax right: it keeps telling me
 date: the argument `1321251520' lacks a leading `+';

~ $ function foo {
 date -d @$1
 }
 ~ $ foo 1321251520
Mon Nov 14 06:18:40 GMT 2011
~ $ 

Copied and pasted literally from my terminal, which is why you see the  PS2 
continuation prompt on lines 2  3.

Stroller.





[gentoo-user] bash date puzzle

2011-11-13 Thread Philip Webb
To convert a UNIX date to a human-readable version the command is :

  556: ~ date -d @1321251520
  Mon Nov 14 01:18:40 EST 2011
  
I would like to create a Bash alias or function to do this,
but can't get the Bash syntax right: it keeps telling me
date: the argument `1321251520' lacks a leading `+';
when using an option to specify date(s), any non-option
argument must be a format string beginning with `+'
Try `date --help' for more information.

I can't find any explanation for the '@' in the CLI version
nor do various attempts to insert '+', escape '\@' etc succeed.

Can anyone suggest a way to do this ?

-- 
,,
SUPPORT ___//___,   Philip Webb
ELECTRIC   /] [] [] [] [] []|   Cities Centre, University of Toronto
TRANSIT`-O--O---'   purslowatchassdotutorontodotca