summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorPratik Karki <predatoramigo@gmail.com>2018-02-28 15:05:29 +0545
committerGitHub <noreply@github.com>2018-02-28 15:05:29 +0545
commit0bbd9875bccdd9b9830ebdc1415f5fc92c2473d1 (patch)
tree65e2fccb306c64419c056537b56e1fb0dc698f99
parent27765075577bb44ae23f35825db3b7bffc661a3c (diff)
parent2dda26010ab52ecd5d54c6fa1b8701288aaaac2d (diff)
Merge pull request #3001 from Neinei0k/bash-en
[bash/en] Add arrays and alias
-rw-r--r--bash.html.markdown26
1 files changed, 26 insertions, 0 deletions
diff --git a/bash.html.markdown b/bash.html.markdown
index 0c097c27..3f3e49eb 100644
--- a/bash.html.markdown
+++ b/bash.html.markdown
@@ -83,6 +83,25 @@ echo ${Foo:-"DefaultValueIfFooIsMissingOrEmpty"}
# 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.
+# Declare an array with 6 elements
+array0=(one two three four five six)
+# Print first element
+echo $array0 # => "one"
+# Print first element
+echo ${array0[0]} # => "one"
+# Print all elements
+echo ${array0[@]} # => "one two three four five six"
+# Print number of elements
+echo ${#array0[@]} # => "6"
+# Print number of characters in third element
+echo ${#array0[2]} # => "5"
+# Print 2 elements starting from forth
+echo ${array0[@]:3:2} # => "four five"
+# Print all elements. Each of them on new line.
+for i in "${array0[@]}"; do
+ echo "$i"
+done
+
# Brace Expansion { }
# Used to generate arbitrary strings
echo {1..10} # => 1 2 3 4 5 6 7 8 9 10
@@ -155,6 +174,13 @@ then
echo "This will run if $Name is Daniya OR Zach."
fi
+# Redefine command 'ping' as alias to send only 5 packets
+alias ping='ping -c 5'
+# Escape alias and use command with this name instead
+\ping 192.168.1.1
+# Print all aliases
+alias -p
+
# Expressions are denoted with the following format:
echo $(( 10 + 5 )) # => 15