linux tcsh interactive and argv

Joined
Sep 28, 2007
Messages
8
Reaction score
0
Points
1
Hi all,

I have, in a .cshrc file ported from my old unix .alias file, some aliases like this;

alias oneCol 'tr " " "\012" < $1 > $2'

I'm running interactive tcsh on my Tiger OS X, and these aliases fail here, like this;

> oneCol test1 testOut
tcsh: $1: Ambiguous.

I believe this is because argv is not set for these interactive tcsh commands. Is there some way to force argv to be set in OS X tcsh? Or what would an equivalent tcsh alias be? (Please, please, don't tell me to use some other shell.)

Thanks -
 

rman


Retired Staff
Joined
Dec 24, 2002
Messages
12,637
Reaction score
168
Points
63
Location
Los Angeles, California
Your Mac's Specs
14in MacBook Pro M1 Max 32GB 2TB
What I see is that the ' should be a `. I could be wrong thou.
 
OP
N
Joined
Sep 28, 2007
Messages
8
Reaction score
0
Points
1
leading ` instead of '

rman,

I can't make your suggestion work, if I understand you correctly. I tried

alias oneCol `tr " " "\012" < $1 > $2'

also

alias oneCol `tr " " "\012" < $1 > $2`

and

alias oneCol `tr " " "\012" < \$1 > \$2`

LMK if I'm doing something stupid here -
 

rman


Retired Staff
Joined
Dec 24, 2002
Messages
12,637
Reaction score
168
Points
63
Location
Los Angeles, California
Your Mac's Specs
14in MacBook Pro M1 Max 32GB 2TB
Try this

alias oneCol "`tr ' ' '\012' < $1 > $2`"
 
OP
N
Joined
Sep 28, 2007
Messages
8
Reaction score
0
Points
1
/Users/crose1 > alias oneCol "`tr ' ' '\012' < $1 > $2`"
tcsh: Missing name for redirect.
/Users/crose1 > alias oneCol "`tr ' ' '\012' < \$1 > \$2`"
/Users/crose1 > oneCol test1 test1.out
tcsh: test1: Permission denied.
/Users/crose1 > which oneCol
oneCol: aliased to
/Users/crose1 > alias oneCol "tr ' ' '\012' < $1 > $2"
/Users/crose1 > oneCol test1 test1.out
tcsh: Missing name for redirect.
/Users/crose1 > alias oneCol
tr ' ' '\012' < >
/Users/crose1 > alias oneCol "tr ' ' '\012' < \$1 > \$2"
/Users/crose1 > oneCol test1 test1.out
tcsh: : No such file or directory.
/Users/crose1 > alias oneCol
tr ' ' '\012' < \ > \
/Users/crose1 > alias oneCol `tr ' ' '\012' < $1 $2`
tcsh: $1: Ambiguous.
/Users/crose1 > alias oneCol `tr ' ' '\012' < \$1 \$2`
tcsh: $1: No such file or directory.

OK, I give up. Instead, I just put this in my bin directory, instead, as a file named oneCol (and then gave it execute permission, and did a rehash).

!#/bin/sh
tr ' ' '\012' < $1 > $2

This command isn't such a great example, because it's a command you might otherwise want to pipe to something else (but because of the argv redirection, you can't). There are other commands which are much more appropriate for this, and for each of those, I'll just move them each to their own file in my local bin dir.

Thanks rman for trying to help me out - I appreciate it.
 
OP
N
Joined
Sep 28, 2007
Messages
8
Reaction score
0
Points
1
FINALLY, I have the answer I was looking for. Here is a correct alias that uses command line arguments;

alias oneCol 'tr " " "\012" < \!:1 > \!:2'

I don't know why this works, but it does. I found a syntax example for this in article 10.03 of O'Reilly's UNIX POWER TOOLS.

I realize it is a waste of time to agonize over something that there's a dozen different ways to otherwise do, but I feel so much better having found the answer I originally set out to look for.
 

rman


Retired Staff
Joined
Dec 24, 2002
Messages
12,637
Reaction score
168
Points
63
Location
Los Angeles, California
Your Mac's Specs
14in MacBook Pro M1 Max 32GB 2TB
Glad to see you found a solution. I would have never thought of the bang colon.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top