zsh function syntax.

zsh function syntax.

Post by Hong Yeh Ryan Wo » Mon, 09 Aug 1993 06:13:55



Hi, can any zsh users' tell me what is wrong with the following
function:
------------------------------------------------------------------------------
function del() {
   if (($# == 0)) {                            
      echo "usage: del [filename]..."
   } elif (($# == 1)) {
      echo hahaaha
   } else {
      echo foobar....
      mv $* /.trash
   }
Quote:}

------------------------------------------------------------------------------
According to the man page, the syntax of the conditional statements is
correct. so what is wrong here ? is it w/ the function ?

here is the error I got:
------------------------------------------------------------------------------
root / [39] . .zsh_aliases                                             [7:07am]
.zsh_aliases: parse error near `)' [50]
hahaaha
.zsh_aliases: parse error near `}' [52]
foobar....
Usage: mv [options] source dest
       mv [options] source... directory
Options:
       [-bfiuv] [-S backup-suffix] [-V {numbered,existing,simple}]
       [--backup] [--force] [--interactive] [--update] [--verbose]
       [--suffix=backup-suffix] [--version-control={numbered,existing,simple}]
.zsh_aliases: parse error near `}' [55]
.zsh_aliases: parse error near `}' [56]
------------------------------------------------------------------------------

Also, another problem :-)

function chpwd () { print -Pn '^[]2;%~^G' }

does not change my xterm title bar to display my PROMPT, could somebody
please help ..

Thanks a lots

--

- UNIX Users: try this and cry :-)                        
- kill -9 `ps auxw | grep "\`whoami\`" | awk '{print $2}'`
- MS-DOS / MS-WINDOWS User: you have to reboot your machine !!!

 
 
 

zsh function syntax.

Post by Qiegang Lo » Mon, 09 Aug 1993 05:32:38



Quote:

> Hi, can any zsh users' tell me what is wrong with the following
> function:
> ------------------------------------------------------------------------
> function del() {
>    if (($# == 0)) {                                
>       echo "usage: del [filename]..."
>    } elif (($# == 1)) {
>       echo hahaaha
>    } else {
>       echo foobar....
>       mv $* /.trash
>    }
> }
> --------------------------------------------------------------------------

You need to put a pair of "( " and " )" around arithmetic evaluation
"(($# == 0))" if you use c-like "if", like this:

function del() {
   if ( (($# == 0)) ) {                        
      echo "usage: del [filename]..."
   } elif ( (($# == 1)) ) {
      echo hahaaha
   } else {
      echo foobar....
      mv $* /.trash
   }

Quote:}

But I would prefer

function del() {
   if (($# == 0)); then
      echo "usage: del [filename]..."
   elif (($# == 1)); then
      echo hahaaha
   else
      echo foobar....
      mv $* /.trash
   fi

Quote:}

or

function del() {
   if [[$# -eq 0]]; then
      echo "usage: del [filename]..."
   elif [[$# -eq 1]]; then
      echo hahaaha
   else
      echo foobar....
      mv $* /.trash
   fi

Quote:}

--
(import std:*disclaimer*)

 
 
 

zsh function syntax.

Post by John C. Fowl » Fri, 13 Aug 1993 06:44:24




>> Hi, can any zsh users' tell me what is wrong with the following
>> function:
>> ------------------------------------------------------------------------
>> Program deleted
>> --------------------------------------------------------------------------

>You need to put a pair of "( " and " )" around arithmetic evaluation
>"(($# == 0))" if you use c-like "if", like this:
>   [stuff deleted]
>But I would prefer
>   [stuff deleted]
>--
>(import std:*disclaimer*)

Have you tried simply setting up an alias?  In csh, it's simply:

alias rm 'mv !* ~/.trash'

Maybe easier....

maybe not....

john...

  _ \__
  /( __>  
 //| \    
///___)  Shadowfax...

 
 
 

1. Seeking example shell syntax for bash, csh, zsh, sh

hello, all.

i am looking for a document that gives example shell
syntax for flow-of-control constructs, variable evaluation,
&c. for the shells listed above; i've looked at the various
FAQ's, but none seems to give sample shell syntax.

anyone know of a website, or ftp-able document, that
contains this type of info?

thanks,
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

2. linux ifconfig

3. zsh: how to check script syntax?

4. Send 20 FREE Pages of Fax to any Fax machines in the World!

5. zsh syntax [] as opposed to [[]]

6. X windows terminal emulation for Windows

7. equivalent zsh syntax for bash command

8. NEWBIE: Network setup

9. zsh function does not get in foreground

10. zsh: incompatibility on autoloading functions

11. zsh: Bind a key to an arbitrary function?

12. zsh typeset inside a function

13. zsh function/positional parameter question...