You can do something like:

#!/bin/sh

if [ ! `which fish` ]; then
  echo "You need to download fish."
  echo "Go to http://www.fishshell.com.";
  exit 1
fi

fish << END

echo Run via $SHELL
# fish script here

END

However, I think it's more in keeping with the Unix philosophy to
specify the fish dependency in the #! line and let the shell complain
if it doesn't exist.

Also, you might be better off writing scripts intended for wide
distribution in a more popular scripting language (like bash), and
save fish for fish functions and the like where you don't have to
worry about fish not being available. (I think the fish docs might
even say this at some point.)




Michael

On Fri, Oct 2, 2015 at 2:09 PM, Daniel Roskams
<rocket.peng...@riseup.net> wrote:
> This is my first time posting to this list, so, apologies if this
> question has already been asked or answered before.
>
> Because (sadly) most people using UNIX-like operating systems do not
> have fish installed, it is generally a bad idea to write scripts in fish
> for everyone to use, because fish (luckily) deviates from the Bourne
> shell syntax in some ways.
>
> Therefore, if I distribute a script written in fish, I want to be able
> to include a header at the top so I can check if fish is executing the
> shell. If not, either run the bourne shell version, or print an error
> message. If fish IS running the script, just continue.
>
> It would look something like this, in pseudocode.
>
> if fish is in $PATH
>         fish $THIS_FILE
> end
>
> if $FISH_VERSION is zero length
>         echo "You need to download fish."
>         echo "Go to http://www.fishshell.com.";
>         exit 1
> end
>
> ...
> rest of fish script here
> ...
>
> exit 0
>
> The reason that I want to do this is because most people will just get
> rid of my program if they don't know what to do with it. Unfortunately,
> most people have not even /heard/ of fish.
>
> --
> Daniel Roskams (rocketpenguin) <rocket.peng...@riseup.net>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Fish-users mailing list
> Fish-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/fish-users

------------------------------------------------------------------------------
_______________________________________________
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to