simple shell problem

simple shell problem

Post by Ian » Thu, 24 Oct 2002 01:47:54



Hi, I have a very simple C shell script that does not do what I expect:
It is in a file called test.
when I enter--
$ test 1 2 3 enough  ... ... ... also tried ./test 1 2 3 enough
I get: bad number argv.
Can anyone please help with what is going wrong?
thanking you in advance.

 #!/bin/csh -f
    set x = $argv[1]; shift argv
    foreach y ( $argv[*] )
      set z = $x
      while ( $z )
        echo -n "$y, "

      end
      echo \!
    end

 
 
 

simple shell problem

Post by Barry Margoli » Thu, 24 Oct 2002 02:06:34




>Hi, I have a very simple C shell script that does not do what I expect:
>It is in a file called test.

It's not a good idea to call your program "test", as this is a built-in in
most shells.

Also, before you get into bad habits, you should learn to script in a
better language than C shell.  It's OK as an interactive shell, but a poor
scripting language.

Quote:>when I enter--
>$ test 1 2 3 enough  ... ... ... also tried ./test 1 2 3 enough
>I get: bad number argv.
>Can anyone please help with what is going wrong?
>thanking you in advance.

> #!/bin/csh -f
>    set x = $argv[1]; shift argv

The argument to "shift" must be a number -- it's the number of places to
shift.  You can't specify which variable to shift, it always operates on
argv.

>    foreach y ( $argv[*] )
>      set z = $x
>      while ( $z )
>        echo -n "$y, "

>      end
>      echo \!
>    end

--

Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

1. SUMMARY: simple shell for a simple man

My original question:

I got many answers, some using awk, sed, and tr to massage the output
of the date command, some using shell variables, etc., but the

Grubin). Unfortunately I lost a few replies, so I don't know who it
was that suggested that I use the at command rather than putting this

Barnett) made the very sensible suggestion that I have the dates come
out year month day for sorting purposes. Here's what I ended up with:

# !/bin/sh
mv /home/khonshu/sjsk/outgoing.record /home/khonshu/sjsk/msgs/mailout.`date '+%y%m%d'`
at 23:59 sat /home/khonshu/sjsk/bin/stamp_mail

I had my boss (for whom this shell is intended) invoke this by doing:

        at 23:59 sat bin/stamp_mail

One question I have concerns the paths. As you can see, just to be on
the safe side, I gave full path names in the shell. If this is
executed from /home/khonshu/sjsk the very first time, will it always
be executed from their (i.e. will the at command reinvoke it in the
same directory?), or is it better to be safe as I have done here?

Any comments welcome. I'll repost the summary if I get a lot of
suggestions and comments that improve the situation.

Thanks to all that responed.
                                Ed
--

2. PC164 SRM Redhat 7.2

3. Simple Shell Scripting Problem

4. Need XF86Config.

5. Simple Shell Script with Little Problem

6. AIX Manuals

7. simple shell crontab problem

8. Help Please Setting User Default Job Priorities

9. simple shell script problems

10. Simple C-shell problem, please help

11. simple shell script problem

12. Simple Shell Script Problem ??

13. simple date problem, simple solution?