Variables in Bash script language have following properties:
Interesting with $ sign in Bash is, if you put something in brackets after $ this will be interpreted as interpreter command.
Important thing about variables is that you can use local variables in functions, using keyword local.
- They haven't data type
- There is no need to declare variable
#!/bin/bashThis simple example will output sentence Hello World!
Var1 = "Hello World!"
echo $Var1
Interesting with $ sign in Bash is, if you put something in brackets after $ this will be interpreted as interpreter command.
#!/bin/bashThis simple example will put output from ls -la command in $Var1 variable and then print content on screen.
Var1= $(ls -la)
echo $Var1
Important thing about variables is that you can use local variables in functions, using keyword local.
local Var1="Local variable"
Builtin variables
Bash have Built-in variables, some of them are:
- $BASH - Path to the Bash binary
- $BASHPID - Process ID of Bash
- $BASH_VERSION - Version of Bash
- $HOME - Home directory of user
- $MACHTYPE - Machine type
- $PATH - Path to binaries
- $PWD - Working directory
- $SECONDS - number of second while script is running
- $UID - User ID number
- $0,$1 ... - Command line arguments
- $# - Number of command line arguments
No comments:
Post a Comment