Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Update README.md #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ See something incorrectly described, buggy or outright wrong? Open an issue or s
* [Random array element](#random-array-element)
* [Cycle through an array](#cycle-through-an-array)
* [Toggle between two values](#toggle-between-two-values)
* [join string into lists](#join-string-into-lists)
* [LOOPS](#loops)
* [Loop over a range of numbers](#loop-over-a-range-of-numbers)
* [Loop over a variable range of numbers](#loop-over-a-variable-range-of-numbers)
Expand Down Expand Up @@ -759,6 +760,43 @@ cycle() {
}
```

## join string into lists

This function is same to the python' function `join` or perl function `join`.

+ function

```bash
function join_list {
local delimiter=$1
local list=($@)
echo ${list[@]}
local len=${#list[@]}
(( tail_1 = $len - 1 ))
(( tail_2 = $len - 2 ))
if [ ${len} -gt 1 ];
then
for i in $(seq 0 ${tail_2});
do
local item=${list[${i}]}
echo -n ${item}${delimiter}
done
echo ${list[${tail_1}]}
else
echo ${list[0]}
fi
}
```

+ usage

```bash
$ l=$(seq 0 10)
$ join_list , ${l[@]}

0,1,2,3,4,5,6,7,8,9,10
```

<!-- CHAPTER END -->

<!-- CHAPTER START -->
Expand Down