diff --git a/Programming_Languages/Shell/Loops_in_bash.md b/Programming_Languages/Shell/Loops_in_bash.md new file mode 100644 index 0000000..26fb7b2 --- /dev/null +++ b/Programming_Languages/Shell/Loops_in_bash.md @@ -0,0 +1,15 @@ +--- +categories: + - Programming Languages +tags: + - shell +--- + +# Loops in bash + +```bash +for element in "${arr[@]}" +do + echo "$element" +done +``` diff --git a/Programming_Languages/Shell/Split_into_array.md b/Programming_Languages/Shell/Split_into_array.md index c577dad..6c0ae0b 100644 --- a/Programming_Languages/Shell/Split_into_array.md +++ b/Programming_Languages/Shell/Split_into_array.md @@ -9,8 +9,7 @@ tags: ## `readarray` -`readarray` makes it really easy to split input into an array. - +`readarray` makes it really easy to split input into an array based on new lines. Say we have this file as input: ``` @@ -48,3 +47,18 @@ is > The _-t_ flag removes the trailing newline Add more: https://linuxhint.com/split-string-array-bash/ + +## `read` + +For different delimiters we have to use `read`, combined with `IFS` the **Internal Field Separator**. + +For example, to split by comma: + +```plaintext +# comma-input.txt +something, something else, something more +``` + +```bash +IFS=',' read -a arr < ./comma_inputs.txt +```