Bash:Variables: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
No edit summary |
||
| Line 14: | Line 14: | ||
echo This shell is interactive | echo This shell is interactive | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==Arithmetics== | |||
Bash and ksh only work with integers. | |||
;+, -, *, /, % | |||
:add, substract, multiply, divide, modulo. | |||
;<nowiki>**</nowiki> | |||
:For bash, Exponentiation | |||
;10#00012 | |||
:For bash, force the figure (00012) to be interpreted as decimal. Figures starting with 0 are considered octal by default. | |||
;expr <expr> | |||
:Voer expr uit, bij boolean wordt 1 (onwaar) of 0 (waar) gegeven | |||
;((VAR=x+y)) | |||
;let VAR=x+y | |||
;VAR=$((x+y)) | |||
;VAR=$(expr x + y) | |||
:Calculate and assign to VAR | |||
;let VAR+=2 | |||
:Add two to VAR | |||
Revision as of 22:16, 30 November 2018
Bash is a *nix shell. Much more is still in the antiperfect unix site.
To check within a startup script (like .bashrc) whether or not Bash is running interactively. Test if $- has an 'i' in it or if $PS1 (the prompt) exists.
case "$-" in
*i*) echo This shell is interactive ;;
*) echo This shell is not interactive ;;
esac
if [ -z "$PS1" ]; then
echo This shell is not interactive
else
echo This shell is interactive
Arithmetics
Bash and ksh only work with integers.
- +, -, *, /, %
- add, substract, multiply, divide, modulo.
- **
- For bash, Exponentiation
- 10#00012
- For bash, force the figure (00012) to be interpreted as decimal. Figures starting with 0 are considered octal by default.
- expr <expr>
- Voer expr uit, bij boolean wordt 1 (onwaar) of 0 (waar) gegeven
- ((VAR=x+y))
- let VAR=x+y
- VAR=$((x+y))
- VAR=$(expr x + y)
- Calculate and assign to VAR
- let VAR+=2
- Add two to VAR