Hi guy! , I am learning shell script from howtoforge tutorial, in my case I use sh, my operating system has a bash by default, but I want to use sh, them I write an example: #!/bin/sh in the firt line, because in Debian I see in /bin sh also (/bin/sh) the same with bash, all a good many command is good, but when I use: #!/bin/sh echo $PWD echo $USER echo $OSTYPE sh or ./myscript.sh I see all good, but OSTYPE nothing , but when I use bash as my shell is good, but with sh nothing, I want to know, OSTYPE does not exit in sh shell? thank youfor you reply.
OSTYPE is a bash variable, please see: man bash command for a full list of all variables that are built into the bash shell. If you dont get an output for a variable in sh, then this variable does not exist in the sh shell.
IIRC default shell on debian is dash (/bin/sh is symlinked to it). If you want to use Bash then use Code: #!/usr/bin/env bash That's what is recommended by the #bash channel on freenode. I've found one case where /usr/bin/env is required and that's NixOS. NixOS provides atomic upgrades and hence binaries are no necessarlily in standard locations but in the nix store somewhere. So if you boot into a previous configuration or alternate configuration you could be using the wrong bash binary when you use /bin/bash. However the environment variable will use the correct one for that configuration.