Mac Forums

Mac Forums (http://www.mac-forums.com/forums/)
-   Running Windows (or anything else) on your Mac (http://www.mac-forums.com/forums/running-windows-anything-else-your-mac/)
-   -   linux tcsh interactive and argv (http://www.mac-forums.com/forums/running-windows-anything-else-your-mac/96449-linux-tcsh-interactive-argv.html)

newdaddy 02-11-2008 11:08 AM

linux tcsh interactive and argv
 
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 02-11-2008 07:07 PM

What I see is that the ' should be a `. I could be wrong thou.

newdaddy 02-12-2008 09:15 AM

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 02-13-2008 01:28 PM

Try this

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

newdaddy 02-14-2008 10:34 AM

/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.

newdaddy 02-14-2008 11:00 AM

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 02-14-2008 03:59 PM

Glad to see you found a solution. I would have never thought of the bang colon.


All times are GMT -4. The time now is 08:24 AM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.