mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-15 03:06:16 +02:00
Improve bash variable info
This commit is contained in:
@@ -36,8 +36,22 @@ VARIABLE = "Some string"
|
|||||||
# Using the variable:
|
# Using the variable:
|
||||||
echo $VARIABLE
|
echo $VARIABLE
|
||||||
echo "$VARIABLE"
|
echo "$VARIABLE"
|
||||||
|
echo '$VARIABLE'
|
||||||
# When you use the variable itself — assign it, export it, or else — you write
|
# When you use the variable itself — assign it, export it, or else — you write
|
||||||
# its name without $. If you want to use variable's value, you should use $.
|
# its name without $. If you want to use variable's value, you should use $.
|
||||||
|
# Note that ' (single quote) won't expand the variables!
|
||||||
|
|
||||||
|
# String substitution in variables
|
||||||
|
echo ${VARIABLE/Some/A}
|
||||||
|
# This will substitute the first occurance of "Some" with "A"
|
||||||
|
|
||||||
|
# Bultin variables:
|
||||||
|
# There are some useful builtin variables, like
|
||||||
|
echo "Last program return value: $?"
|
||||||
|
echo "Script's PID: $$"
|
||||||
|
echo "Number of arguments: $#"
|
||||||
|
echo "Scripts arguments: $@"
|
||||||
|
echo "Scripts arguments separeted in different variables: $1 $2..."
|
||||||
|
|
||||||
# Reading a value from input:
|
# Reading a value from input:
|
||||||
echo "What's your name?"
|
echo "What's your name?"
|
||||||
|
Reference in New Issue
Block a user