On Tue, Feb 23, 2010 at 08:23, Rick Cogley <[email protected]> wrote: > Hello - I’m new to fish and this list, and have just installed it from > macports to an OS X 10.6 system. Two newbie questions: > > I read I can install functions for all users in /etc/, but my > $fish_function_path references only this: > /Users/rcogley/.config/fish/functions /opt/local/etc/fish/functions > /opt/local/share/fish/functions > > Where should I put functions I want to install for everyone? My /etc has > nothing fish-related. > Your fish was installed under /opt, so instead of using "/etc/fish/functions" you have "/opt/local/etc/fish/functions".
But as I explain below, you probably don't want to write functions, but normal scripts. As usual, scripts should be put somewhere on $PATH. > Secondly, I know how to execute a bash script, for instance doing > ./somescript.sh but how do I do that for a fish script? And, is a fish script > equivalent to a fish “function” in that I would convert bash scripts to > something.fish files and put them in the functions folder? > Scripts and functions are different concepts and both are supported by both shells. So the natural way to rewrite bash scripts would be as fish scripts - but you don't have to! **You can just run your existing bash scripts from fish!** Scripts explanation (pardon if I explain things you already know): A script is a program that is directly executed by an interpreter (instead of being compile to a binary executable). On unix, this is arranged by starting with file with a "#!" line - e.g. "#!/bin/bash" for bash scripts. Just for fun, run "grep '#!' /usr/bin/*" - you'll discover that hundreds of programs on your system are actually scripts, about half of them written in sh/bash and most others in perl and python. If fish was more popular, many would also be written in fish :-). The important point here is that you don't care - any script can be run from any shell or program (e.g. double-clicked in the file manager)! So you don't need to rewrite existing bash scripts for fish, you can use them as is. But future scripts you'll probably want to write in fish (and they'll work from bash too). Just put "#!/usr/bin/fish" on the first line, do "chmod +x script.fish", and it becomes an executable program. You can run it as "./script.fish", "/full/path/script.fish" - or just "script.fish" from anywhere if it sits somewhere along $PATH. (or however you decide to call it, i usually don't give my scripts any extension). Functions explanation: Shell functions are not executable files, but a concept managed entirely by the shell. (Maybe you're more familar with the concept of a shell "alias" - same idea, but a "function" is more flexible.) The benefit is that a function is executed *in the current shell*, and can affect it - set variables, change the current directory, etc. (Doing "set" or "cd" in a script would only affect the sub-shell that executes the script and not the shell that launched it.) The drawback is that you can't run it from other shells/programs. So it's mostly used for customization of your shell. Functions are not looked up along $PATH - they are defined by the "function" command, and live in a separate namespace inside the shell. So normally, any function you'd want to use on future logins would have to be defined in your init file. (Remember how bash init files are usually full of alias definitions?) Now fish has a twist, which might be the part that confused you. Fish generally tries to free you from bothering with init files. One part of it are universal variables - just do "set -Ux VAR value" and the FOO environment variable will be set accross all your logins - without ever touching an init file. The second part of it is *function autoloading*. Instead of writing "function something; ...; end" in your init file, you can write it (including the "function" command!) in "something.fish" (here the extension does matter), located somewhere along $fish_function_path - and on the first attempt to run the function, its definition will be loaded from that file. Also, the "funcsave" command will write such a file automatically, allowing you to define a function interactively and make it available for future logins without ever opening an editor. This makes functions feel slightly like scripts - just putting a file in specific directories makes a new command accessible. But they are still functions - they work *only from fish*, and the only reason to write them instead of normal scripts is to affect the state of the current shell. -- Beni Cherniavsky-Paskin <[email protected]> P.S. do we want some explanation along these lines in the docs/FAQ? ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ Fish-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/fish-users
