Compare commits

...

3 Commits

Author SHA1 Message Date
daryl
d9647ceab1 Merge pull request 'add_bash_array_snippet' (#1) from add_bash_array_snippet into master
Reviewed-on: https://gitea.gordon.on.net/daryl/CodeSnippets/pulls/1
2022-07-01 22:12:19 +09:30
daryl
79034b2888 Update 'bash/README.md' 2022-07-01 11:40:06 +09:30
daryl
a44d979737 Add 'bash/array_append.bash' 2022-07-01 11:39:26 +09:30
2 changed files with 17 additions and 0 deletions

View File

@@ -4,6 +4,10 @@
Handling command line argument / parameter parsing at the beginning of a script. Handling command line argument / parameter parsing at the beginning of a script.
## array_append.bash
How to declare an array, append new elements, iterate over the array for processing.
## booleans.bash ## booleans.bash
BASH doesn't actually have booleans, but there's tricks to make variables behave enough like bools to be useful. BASH doesn't actually have booleans, but there's tricks to make variables behave enough like bools to be useful.

13
bash/array_append.bash Normal file
View File

@@ -0,0 +1,13 @@
#!/bin/bash
# Declare a string array
arrVar=("AC" "TV" "Mobile" "Fridge" "Oven" "Blender")
# Add new element at the end of the array
arrVar+=("Dish Washer")
# Iterate the loop to read and print each array element
for value in "${arrVar[@]}"
do
echo $value
done