Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to detect OS in fish shell akin to the OSTYPE variable in bash?

Right now I'm forced to resort to using uname to get the operating system name and it works. But in bash there is the OSTYPE environment variable that is automatically set and I was wondering if there is something similar.

like image 506
RubenLaguna Avatar asked Oct 08 '14 13:10

RubenLaguna


People also ask

Is fish compatible with bash?

Regular bash scripts can be used in fish shell just as scripts written in any language with proper shebang or explicitly using the interpreter (i.e. using bash script.sh ). However, many utilities, such as virtualenv, modify the shell environment and need to be sourced, and therefore cannot be used in fish.

Does fish read Bashrc?

bashrc and . profile, this file is always read, even in non-interactive or login shells. The “~/. config” part of this can be set via $XDG_CONFIG_HOME, that's just the default.

Is fish better than bash?

Fish, or the “Friendly Interactive Shell,” is the most user-friendly and interactive shell, in my opinion. It is much more customizable than Zsh and Bash. It has a ton of cool features like consistent syntax, nice tab completion and syntax highlighting, is easy to pick up and use, and has excellent runtime help.


1 Answers

From the fish user documentation it seems that the canonical way to execute code conditionally depending on the operating system type is using a switch statement with the uname results. See example:

switch (uname)
    case Linux
            echo Hi Tux!
    case Darwin
            echo Hi Hexley!
    case FreeBSD NetBSD DragonFly
            echo Hi Beastie!
    case '*'
            echo Hi, stranger!
end
like image 65
RubenLaguna Avatar answered Sep 28 '22 13:09

RubenLaguna