From ce7ef719e23bf3bd7184b45c4fee1357557be8ed Mon Sep 17 00:00:00 2001 From: thomasabishop Date: Wed, 25 Jan 2023 19:24:47 +0000 Subject: [PATCH] Autosave: 2023-01-25 19:24:47 --- .../Hardware_Description_Language.md | 2 +- .../Shell => Linux}/Cron.md | 0 .../Shell/Archiving_and_compressing_files.md | 0 .../Shell/Split_into_array.md | 50 +++++++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) rename {Programming_Languages/Shell => Linux}/Cron.md (100%) delete mode 100644 Programming_Languages/Shell/Archiving_and_compressing_files.md create mode 100644 Programming_Languages/Shell/Split_into_array.md diff --git a/Computer_Architecture/Hardware_Description_Language.md b/Computer_Architecture/Hardware_Description_Language.md index b3cb55a..2c181c4 100644 --- a/Computer_Architecture/Hardware_Description_Language.md +++ b/Computer_Architecture/Hardware_Description_Language.md @@ -29,7 +29,7 @@ We will create an HDL program for an XOR gate that is implemented through the fo Here is our HDL file: -```vhdl +``` /* Xor gate If a!=b out=1 else out=0 */ diff --git a/Programming_Languages/Shell/Cron.md b/Linux/Cron.md similarity index 100% rename from Programming_Languages/Shell/Cron.md rename to Linux/Cron.md diff --git a/Programming_Languages/Shell/Archiving_and_compressing_files.md b/Programming_Languages/Shell/Archiving_and_compressing_files.md deleted file mode 100644 index e69de29..0000000 diff --git a/Programming_Languages/Shell/Split_into_array.md b/Programming_Languages/Shell/Split_into_array.md new file mode 100644 index 0000000..c577dad --- /dev/null +++ b/Programming_Languages/Shell/Split_into_array.md @@ -0,0 +1,50 @@ +--- +categories: + - Programming Languages +tags: + - shell +--- + +# Splitting input into an array + +## `readarray` + +`readarray` makes it really easy to split input into an array. + +Say we have this file as input: + +``` +123 +456 +789 +``` + +Then we can split like so: + +```bash +readarray -t name_for_array < ./input.text + +# Print all elements +echo "${name_for_array[@]}" + +# Print element by index + +echo "${name_for_array[1]}" +456 +``` + +If we want to read direct from string within bash file: + +```bash +readarray -t new_name_for_array <<< "here +is +some +text" + +echo "${new_name_for_array[1]}" +is +``` + +> The _-t_ flag removes the trailing newline + +Add more: https://linuxhint.com/split-string-array-bash/