if-then-else in csh alias?

if-then-else in csh alias?

Post by mk.. » Thu, 02 Aug 1990 04:03:00



I want to define an alias like:

alias show 'if ($?\!:1) then \
                if ($#\!:1) then \
                        echo "\!:1 = $\!:1" \
                else \
                        echo "\!:1 is set" \
                endif \
        else \
                echo "\!:1 is not set" \
        endif'

But the "\" at the end of each line doesn't embed a newline into the alias
as needed for the if-then-else to work right.

Is there any way to embed newlines into alias definitions?

Mike Khaw
--

usenet:    {hplabs|sun|ucbvax|decwrl|sri-unix}!mkhaw%teknowledge-vaxc.arpa
USnail:    Teknowledge Inc, 1850 Embarcadero Rd, POB 10119, Palo Alto, CA 94303

 
 
 

if-then-else in csh alias?

Post by Theodore Y. Ts' » Thu, 02 Aug 1990 23:48:00



>Is there any way to embed newlines into alias definitions?

Let me expand the question.  Is there a way to put a *foreach* in an alias
definition. Try doing this:

alias test      'foreach i (\!*) \
                 echo $i \
                 end'

And watch your (mine, at least) csh core dump.  I think it has to do
with how csh determins whether you're on a interactive session or not.
The same alias executed from a shell script seems to work well.

P.S.  Don't try this on your login shell.
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
Theodore Ts'o                           |
mit-eddie!mit-athena!tytso              |     M.I.T.,


 
 
 

if-then-else in csh alias?

Post by Randy Orris » Thu, 02 Aug 1990 19:34:00


on the side, this dumps core on an Encore running UMAX 4.2:

        mkdir x
        mkdir y
        set home=x/y    # not absolute!
        cd
        cd ../..        # reference to $home?
        ***BOOM***

I know it's a stupid thing to do, but it shouldn't dump core.  actually, the
cd ../.. should work, it's cd by itself that should have trouble, though just
with not being able to find $home.
        -randy
(Just tried it on our vanilla [for now] 4.3 VAX - another core dump!)
--
Randy Orrison, University of Minnesota School of Mathematics
UUCP:   {ihnp4, seismo!rutgers!umnd-cs, sun}!umn-cs!randy


 
 
 

if-then-else in csh alias?

Post by jb.. » Thu, 02 Aug 1990 02:01:00



>on the side, this dumps core on an Encore running UMAX 4.2:

>    mkdir x
>    mkdir y

I think you meant "mkdir x/y" here.

Quote:>    set home=x/y    # not absolute!
>    cd
>    cd ../..        # reference to $home?
>    ***BOOM***

This core dumps csh on a Masscomp running RTU v3.1 also.

Quote:>(Just tried it on our vanilla [for now] 4.3 VAX - another core dump!)

That's the beauty of Unix: it's portable!  :-)

--

              {uunet,ucbvax,sun,decwrl,<smart-site>}!epimass.epi.com!jbuck

 
 
 

if-then-else in csh alias?

Post by g.. » Thu, 02 Aug 1990 18:59:00



>On our VAX8650 running Ultrix 2.0-1 the "first" cd command fails with a
>"cannot change to home directory"!

That's because there indeed was no directory x/y.
The mkdir should have made x then x/y, not x then y.
 
 
 

if-then-else in csh alias?

Post by j.. » Sun, 02 Sep 1990 12:48:00




>>on the side, this dumps core on an Encore running UMAX 4.2:

>>        mkdir x
>>        mkdir y
>I think you meant "mkdir x/y" here.
>>        set home=x/y    # not absolute!
>>        cd
>>        cd ../..        # reference to $home?
>>        ***BOOM***

>This core dumps csh on a Masscomp running RTU v3.1 also.
>>(Just tried it on our vanilla [for now] 4.3 VAX - another core dump!)

I just tried it on a Intel 310/286 box with Xenix 3.4 with csh.......
  It worked OK there putting me back in the directory I started from.
        mkdir x x/y
        set home=x/y
        cd ..
        cd
  Causes the error message:   'x/y: No such file or directory'

What so hard about that?

Joel Clark
Intel Scientific Computers                      joel%isc.intel.com
(503) 629-7732                          {tektronix}!ogcvax!intelisc!joel
My employer will disavow any knowledge of my actions....Hi Ollie.

 
 
 

if-then-else in csh alias?

Post by sch.. » Sun, 02 Sep 1990 19:06:00


Csh bomber:

mkdir x x/y
set home = x/y
cd x/y
cd ../..
*** BOOM! ***
core dumped

I also tried it on a VAX 750, 8650 and 785 running 4.2, 4.3 BSD, and Ultrix.
They *ALL* died.  Well, UNIX is portable is that sense..... :-)

I guess the thing is that, when you say cd ../.., $home cannot go that
far, and the pointer runs off the head of the string 'x/y'.  (First ..,
go to 'x' and next .., where? Oops!)

I hope you guys keep posting interesting things like this..... (:->

- Stephen

 
 
 

if-then-else in csh alias?

Post by Hans Muld » Sun, 02 Sep 1990 13:00:00


A quicker way to get csh to drop core:

$ HOME='xxx???yyy' csh
(null): No match.
Illegal instruction
$

Also works with PATH, TERM and USER.

For a change, you could try:

$ HOME='`/bin/date >/dev/tty`' csh
Fri Sep  4 17:50:22 MET DST 1987

This causes csh to hang.  It also leaves you a zombie process.  Apparently
csh does not wait for the child process it just forked off.
Note that you have to specify a full path name, because $path has not yet
been set, as you can observe by trying HOME='`set >/dev/tty`'.

                                        Hans Mulder

 
 
 

1. csh: if-then-else-endif in csh alias?


: I am converting some Korn Shell scripts to Csh.

Leave them in ksh.  Especially if they work.

: The Korn Shell scripts have some simple shell functions that use
: if-then-else-fi control structures in them. Is there no way to do
: this with a Csh alias? I know that you can do plain one-line if
: constructs in a Csh alias, but the bug in the pudding comes when
: I try to do the then-else-endif.

That's because you can't do one-line if-then-else-endif constructs in
csh.  You just can't.  It's impossible.  Same goes for foreaches.

Don't write shell scripts in csh.  It's broken.  Really.  It should've
never gotten out in the first place.  There's a detailed FAQ.

--Dave

2. news: IBM to distribute GNU/Linux with its server software

3. Ultra ATA drive supported?

4. if-then-else in a make description file (SHELL=/usr/bin/csh)

5. TORiSAN DVD-ROM hangs system

6. One line If-then-else block in csh possible?

7. Partition problem and D druid

8. Can I nest if-then-else within if-then-else?

9. aliases, aliases, aliases...

10. script alias problem - Re: apache alias and script alias problem

11. csh: alias and nested quotes!!! :-(

12. Building an awk alias in (t)csh