在 .profile linux mint 中编写函数的语法是什么

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

我正在尝试向我的 ~/.profile 文件中添加一个函数。我从 laravel homestead 安装指南中复制它:enter link description here 正如指南所说:

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

如果我这样做 "source .profile" 它工作正常但如果我重新启动我得到:

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

我试过这样删除括号:

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

但我得到:

syntax error near unexpected token `cd'

我的文件上没有shebang,我应该放它吗?

您删除了错误的项目。符合 POSIX 的函数定义是

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

function(带或不带 ())是从 ksh 借来的 bash 扩展。 source 暗示你是 运行 bash,但是 .profile 被其他不理解 function 关键字的 POSIX 兼容的 shell 使用。