[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Interactive definition of a shell function.



On Thu, Sep 12, 2013 at 08:06:11AM -0700, peasthope@shaw.ca wrote:

||  Suppose a user wants to make shell function such as this.
||    cpST () { cp Source Target }
||  The shell is waiting for a command so it can't be typed 
||  directly at the prompt.

Yes, it can.

||  This also doesn't work.  
||  peter@dalton:~$ dash -c "cpST () { cp Source Target }"
||  dash: 1: Syntax error: end of file unexpected (expecting "}")

The closing } is only recognized where a new command could have
started. Terminate your command with a semicolon.

    cpST () { cp Source Target; }

In your scripts, the } is probably on a new line: the newline before it
then terminates the command:

    cpST(){
        cp Source Target      # <- newline terminates command
    }

Vincent.
-- 
Vincent Zweije <vincent@zweije.nl>   | "If you're flamed in a group you
<http://www.xs4all.nl/~zweije/>      | don't read, does anybody get burnt?"
[Xhost should be taken out and shot] |            -- Paul Tomblin on a.s.r.

Attachment: signature.asc
Description: Digital signature


Reply to: