This builtin command is used to create a new function. A function is a list of commands that will be executed when the name of the function is entered. The function
function hi
echo hello
end
will write hello whenever the user enters hi.
If the user enters any additional arguments after the function, they are inserted into the environment variable array argv.
function ll
ls -l $argv
end
will run the ls command, using the -l option, while passing on any additional files and switches to ls.
function mkdir -d 'Create a directory and set CWD'
mkdir $argv
if test $status = 0
switch $argv[(count $argv)]
case '-*'
case '*'
cd $argv[(count $argv)]
return
end
end
end
will run the mkdir command, and if it is successful, change the current working directory to the one just created.