Autosave: 2023-01-25 19:24:47
This commit is contained in:
parent
8e733409f8
commit
ce7ef719e2
4 changed files with 51 additions and 1 deletions
|
@ -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
|
||||
*/
|
||||
|
|
50
Programming_Languages/Shell/Split_into_array.md
Normal file
50
Programming_Languages/Shell/Split_into_array.md
Normal file
|
@ -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/
|
Loading…
Add table
Reference in a new issue