Notes on the ‘type’ Command in Bash — Not Something you’d Expect coming from Python and Powershell.
The aim of this page📝is to present the
type command in bash, noting there is no object model in bash that one may take for granted coming from Python & Powershell.
- note that
typein bash does not tell you the type of variable you have - like
Bash doesn’t have types in the same way as Python (although I would say that Python has classes rather than types). But bash variables do have attributes that are given (mostly) through declare, but the range of attributes is fairly small. You can find an attribute using declare -p, for example, declare -i creates an integer
- coming from posh/python then, a weird thing may happen
<!-- PYTHON -->
>>> greeting = "hello"
<!-- POSH -->
>>> $greeting = "hello"
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
<!-- BASH -->
>>> echo $greeting
>>> type $greeting
-bash: type: hello: not found
- there are only 5 possible “types” that the
alias→ command is shell alias
keyword→ command is shell reserved word
function→ command is shell function
builtin→ command is shell builtin
file→ command is disk file
- if it is a function
> echo "you passed me" $*
$ prnt fd fdsfsd fs fdsf
you passed me fd fdsfsd fs fdsf
$ type prnt
prnt is a function
echo "you passed me" $*
- in posh,
typeis a built-in alias for