Search code examples
bashhomesteadlinux-mint

What's the syntax to write a function in .profile linux mint


I'm trying to add a function to my ~/.profile file. I'm copying it from the laravel homestead installation guide: enter link description here as the guide says:

function homestead() {
    ( cd ~/Homestead && vagrant $* )
}

if I do "source .profile" it works just fine but if i reboot i get:

Syntax error "(" unexpected and the system don't let me log in anymore

I tried to remove the parenthesis like this:

function homestead{
        cd ~/Homestead && vagrant $*
}

but i get:

syntax error near unexpected token `cd'

I have no shebang on the file, should i put it ?


Solution

  • You removed the wrong item. The POSIX-compliant definition of a function is

    homestead() {
        ( cd ~/Homestead && vagrant $* )
    }
    

    function (with or without the ()) is a bash extension borrowed from ksh. source implies you are running bash, but .profile is used by other POSIX-compliant shells that don't understand the function keyword.