Operating System - HP-UX
1753903 Members
9719 Online
108810 Solutions
New Discussion юеВ

Re: How to get around quotes when defining alias

 
Frank de Vries
Respected Contributor

How to get around quotes when defining alias

I would like to assign a perl one-liner command to an alias eg.
lt=' perl -e \'foreach(@ARGV){$t =localtime ( ( ( stat ( $_ ) ) [9] ) ); printf("%-20s %s\n",$_,$t);}\' *'
sh: Syntax error: `(' is not expected.

This gives an error as he es the second ' as a terminator.
How to get around this ?
Any trick for that ?
Or is it impossible ?
Look before you leap
8 REPLIES 8
OFC_EDM
Respected Contributor

Re: How to get around quotes when defining alias

Hi Frank,

I'd like to test this out on my own system...how are you going to be using this alias?

Cheers
The Devil is in the detail.
Frank de Vries
Respected Contributor

Re: How to get around quotes when defining alias

Not sure if I understand your question,
do you mean where I set the alias ?

I stick it in the /etc/profile so
I have it at my fingertips everywhere.

So when I login I just want to type lt

and that should do the perl one liner
Look before you leap
Dennis Handly
Acclaimed Contributor

Re: How to get around quotes when defining alias

As you learn when using ksh, you want to toss useless aliases. Use functions instead:
==============================================================
function lt {
perl -e 'foreach (@ARGV) {$t =localtime(((stat($_))[9])); printf("%-20s %s\n",$_,$t);}' "$@"
}

lt a*
Torsten.
Acclaimed Contributor

Re: How to get around quotes when defining alias

IMHO he wants to know what it does - what is in $t?

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
VK2COT
Honored Contributor

Re: How to get around quotes when defining alias

Hello,

Ahh, tricky but possible. Interesting design.

One way:

lt="`perl -e 'foreach(@ARGV){$t =localtime ( ( ( stat ( $_ ) ) [9] ) ); printf(\"%-20s %s\n\",$_,$t);}' *`"

Cheers,

VK2COT
VK2COT - Dusan Baljevic
Frank de Vries
Respected Contributor

Re: How to get around quotes when defining alias

Thanks for your answers, looks promising
The perl oneliner just gives the seconds as well as the minutes, thus $t is time
Look before you leap
OFC_EDM
Respected Contributor

Re: How to get around quotes when defining alias

Thanks now I understand what it's doing.
Looks like you have a solution now though.

Cheers
The Devil is in the detail.
OFC_EDM
Respected Contributor

Re: How to get around quotes when defining alias

Frank that works nicely.

I put the lt= line in a script in my home directoy.

then I did alias lt='path/to/script'

Works like a charm
The Devil is in the detail.