mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-14 02:34:17 +02:00
[bash/en] basic parameter expansion, and brace expansion (#1533)
* Added brace expansion as well as basic parameter expansion * frogot my name * Update bash.html.markdown Added to parameter expansion
This commit is contained in:
@@ -11,6 +11,7 @@ contributors:
|
|||||||
- ["Rahil Momin", "https://github.com/iamrahil"]
|
- ["Rahil Momin", "https://github.com/iamrahil"]
|
||||||
- ["Gregrory Kielian", "https://github.com/gskielian"]
|
- ["Gregrory Kielian", "https://github.com/gskielian"]
|
||||||
- ["Etan Reisner", "https://github.com/deryni"]
|
- ["Etan Reisner", "https://github.com/deryni"]
|
||||||
|
- ["Jonathan Wang", "https://github.com/Jonathansw" ]
|
||||||
filename: LearnBash.sh
|
filename: LearnBash.sh
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -54,6 +55,13 @@ echo '$Variable'
|
|||||||
# its name without $. If you want to use the variable's value, you should use $.
|
# its name without $. If you want to use the variable's value, you should use $.
|
||||||
# Note that ' (single quote) won't expand the variables!
|
# Note that ' (single quote) won't expand the variables!
|
||||||
|
|
||||||
|
# Parameter expansion ${ }:
|
||||||
|
echo ${Variable}
|
||||||
|
# This is a simple usage of parameter expansion
|
||||||
|
# Parameter Expansion gets a value from a variable. It "expands" or prints the value
|
||||||
|
# During the expansion time the value or parameter are able to be modified
|
||||||
|
# Below are other modifications that add onto this expansion
|
||||||
|
|
||||||
# String substitution in variables
|
# String substitution in variables
|
||||||
echo ${Variable/Some/A}
|
echo ${Variable/Some/A}
|
||||||
# This will substitute the first occurrence of "Some" with "A"
|
# This will substitute the first occurrence of "Some" with "A"
|
||||||
@@ -68,6 +76,12 @@ echo ${Foo:-"DefaultValueIfFooIsMissingOrEmpty"}
|
|||||||
# This works for null (Foo=) and empty string (Foo=""); zero (Foo=0) returns 0.
|
# This works for null (Foo=) and empty string (Foo=""); zero (Foo=0) returns 0.
|
||||||
# Note that it only returns default value and doesn't change variable value.
|
# Note that it only returns default value and doesn't change variable value.
|
||||||
|
|
||||||
|
# Brace Expansion { }
|
||||||
|
# Used to generate arbitrary strings
|
||||||
|
echo {1..10}
|
||||||
|
echo {a..z}
|
||||||
|
# This will output the range from the start value to the end value
|
||||||
|
|
||||||
# Builtin variables:
|
# Builtin variables:
|
||||||
# There are some useful builtin variables, like
|
# There are some useful builtin variables, like
|
||||||
echo "Last program's return value: $?"
|
echo "Last program's return value: $?"
|
||||||
|
Reference in New Issue
Block a user