Skip to content

Commit 2a3a29b

Browse files
version 2.2.0
1 parent 22552b6 commit 2a3a29b

23 files changed

Lines changed: 1809 additions & 720 deletions

.github/workflows/shellcheck.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: ShellCheck
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
9+
jobs:
10+
shellcheck:
11+
name: ShellCheck
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
18+
- name: Install ShellCheck
19+
run: sudo apt-get install -y shellcheck
20+
21+
- name: Run ShellCheck on library files
22+
run: shellcheck -s bash lib/*
23+
24+
- name: Run ShellCheck on example files
25+
run: shellcheck -s bash example/*
26+
27+
- name: Run ShellCheck on test script
28+
run: shellcheck -s bash test/testTest.sh

README.md

Lines changed: 61 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,56 @@
1-
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/paypalme/whitelight976)
1+
# BashMultiTool
2+
3+
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/paypalme/whitelight976) [![ShellCheck](https://github.com/gavinlyonsrepo/bashmultitool/actions/workflows/shellcheck.yml/badge.svg)](https://github.com/gavinlyonsrepo/bashmultitool/actions/workflows/shellcheck.yml)
4+
5+
## Overview
26

3-
Overview
4-
--------------------------------------------
57
* Name: bashMultiTool
6-
* Description:
8+
* Description:
79

810
A Bash Shell library file for commonly used functions
9-
can be imported into shell scripts to create functional and colorful
11+
can be imported into shell scripts to create functional and colorful
1012
scripts and Terminal users interfaces(TUI).
1113
The library allows user to redefine commonly used functions every time you write a shell script, the library may save a part of the development time.
1214

1315
* Author: Gavin Lyons
14-
* GNU bash: version 5.1.16
15-
16-
Table of contents
17-
---------------------------
16+
* GNU bash: version 5.2.21
1817

19-
* [Installation](#installation)
20-
* [Usage](#usage)
21-
* [Software](#software)
22-
* [Example](#example)
23-
24-
Installation
25-
-----------------------------------------------
18+
## Table of contents
2619

27-
**Linux debian based systems built on Ubuntu 22.04 LTS (Jammy Jellyfish)**
28-
29-
A Personal Package Archives (PPA) has been created on Ubuntu
30-
package building and hosting section of launchpad site
31-
called bashmultitool.
20+
* [Installation](#installation)
21+
* [Usage](#usage)
22+
* [Software](#software)
23+
* [Example](#example)
24+
* [Test](#test)
3225

33-
To install this on your system run commands in terminal
34-
35-
```sh
36-
sudo add-apt-repository ppa:typematrix/bashmultitool
37-
sudo apt update
38-
sudo apt install bashmultitool
39-
```
26+
## Installation
4027

41-
**Arch based System**
28+
### Arch based System
4229

4330
Package available in the Arch Linux user repo AUR
4431

45-
**For other linux systems**
32+
### For other linux systems
4633

47-
Download latest fixed release and run the makefile as per
48-
terminal commands below for version 2.1 latest release at time of writing
49-
Note: If you install with this method you will not be informed of updates
34+
Download latest fixed release and run the makefile as per
35+
terminal commands below for version 2.2.0 latest release at time of writing
36+
Note: If you install with this method you will not be informed of updates
5037
by system.
5138

5239
```sh
53-
curl -sL https://github.com/gavinlyonsrepo/bashmultitool/archive/2.1.tar.gz | tar xz
54-
cd bashmultitool-2.1
40+
curl -sL https://github.com/gavinlyonsrepo/bashmultitool/archive/2.2.0.tar.gz | tar xz
41+
cd bashmultitool-2.2.0
5542
sudo make install
5643
```
5744

58-
Usage
59-
-------------------------------------------
45+
## Usage
6046

6147
Source the library functions from your bash shell scripts like so:
6248

6349
```sh
6450
LIBPATH="/usr/lib/bashmultitool/"
6551
for MYFILE in "$LIBPATH"*;
6652
do
67-
source "$MYFILE"
53+
source "$MYFILE"
6854
done
6955
```
7056

@@ -77,51 +63,60 @@ To access library functions from your shell scripts type:
7763
bmtPrintFunc b_red "Hello World"
7864
```
7965

80-
Software
81-
-----------------------------------------
66+
## Software
8267

83-
Eight separate markdown help files with detailed information,
84-
in documentation folder are available.
85-
For shortcut to each help file click on link in 2nd table below.
68+
Nine separate markdown help files with detailed information,
69+
in documentation folder are available
70+
For shortcut to each help file click on link in 2nd table below.
8671
A script to print library meta data is also installed.
8772

8873
| Installed File Path | Description |
8974
| ------ | ------ |
9075
| /usr/bin/bashmultitool | Script to print library meta data |
91-
| /usr/lib/bashmultitool/bashmultitool/* | 8 library files see next table|
92-
| /usr/lib/bashmultitool/doc/README.md | readme |
93-
| /usr/lib/bashmultitool/doc/bmt*.md | 8 Documentation files see next table |
76+
| /usr/lib/bashmultitool/bashmultitool/* | 9 library files see next table |
77+
| /usr/lib/bashmultitool/doc/README.md | readme |
78+
| /usr/lib/bashmultitool/doc/bmt*.md | 9 Documentation files see next table |
9479

9580
| Library file | Function | Sections | Content | Doc link |
9681
| ---- | ---- | ---- | ---- | ---- |
97-
| bmtPrint | bmtPrintFunc | 101 | Printing text | [bmtPrint help file](documentation/bmtPrint.md)|
98-
| bmtPrompt | bmtPromptFunc | 201-210 | Prompts | [ bmtPrompt help file](documentation/bmtPrompt.md)|
99-
| bmtNetwork | bmtNetworkFunc | 301-302 | Network related | [bmtNetwork help file](documentation/bmtNetwork.md)|
100-
| bmtLinux | bmtLinuxFunc | 401-408 | Linux related | [bmtLinux help file](documentation/bmtLinux.md)|
101-
| bmtFiles | bmtFilesFunc | 501-510 | File related | [bmtFiles help file](documentation/bmtFiles.md)|
102-
| bmtData | btmDataFunc | 601-607 | Data related | [bmtData help file](documentation/bmtData.md)|
103-
| bmtTime | btmTimeFunc | 701-710 | Time related | [bmtTime help file](documentation/bmtTime.md)|
104-
| bmtMisc | bmtMiscFunc | 801-806 | Miscellaneous | [bmtMisc help file](documentation/bmtMisc.md)|
105-
| bmtTest | bmtTestFunc | 901 | internal library test | [bmtTest help file](documentation/bmtTest.md)|
106-
107-
The library contains eight section's, Each section has one file with one function.
108-
Which contains 54 sub-sections in total.
82+
| bmtPrint | bmtPrintFunc | 101 | Printing text | [bmtPrint help file](documentation/bmtPrint.md) |
83+
| bmtPrompt | bmtPromptFunc | 201-210 | Prompts | [bmtPrompt help file](documentation/bmtPrompt.md) |
84+
| bmtNetwork | bmtNetworkFunc | 301-310 | Network related | [bmtNetwork help file](documentation/bmtNetwork.md) |
85+
| bmtLinux | bmtLinuxFunc | 401-410 | Linux related | [bmtLinux help file](documentation/bmtLinux.md) |
86+
| bmtFiles | bmtFilesFunc | 501-510 | File related | [bmtFiles help file](documentation/bmtFiles.md) |
87+
| bmtData | btmDataFunc | 601-610 | Data related | [bmtData help file](documentation/bmtData.md) |
88+
| bmtTime | btmTimeFunc | 701-710 | Time related | [bmtTime help file](documentation/bmtTime.md) |
89+
| bmtMisc | bmtMiscFunc | 801-802 | Miscellaneous | [bmtMisc help file](documentation/bmtMisc.md) |
90+
| bmtTest | bmtDrawFunc | 901-907 | Draw related | [bmtDraw help file](documentation/bmtDraw.md) |
91+
| bmtTest | bmtTestFunc | 1001 | internal library test | [bmtTest help file](documentation/bmtTest.md) |
92+
93+
The library contains eight section's, Each section has one file with one function.
94+
Which contains 70 sub-sections in total.
10995
The sections are grouped per logical function.
110-
Printing, prompting, Linux related, file related,
111-
data related, time related , network related and miscellaneous.
96+
Printing, prompting, Linux related, file related,
97+
data related, time related , draw related, network related and miscellaneous.
11298
The sections are mostly independent of each other
113-
you can source them individually if you wish, however the prompt file *is*
114-
dependent on print. There is also a ninth test section bmtTest used to test library.
99+
you can source them individually if you wish, however the prompt file *is*
100+
dependent on print. There is also a test section bmtTest used to test library.
115101

116-
The repo also contains a *test folder* where a test file used in development are available, one function for each library file. The test file "testTest.sh", runs an semi-automated test on entire library and produces a report. Pass the test file a number between 1-9 , 1-8 correspond to the sections, 9 will test entire library.
117-
118-
Example
119-
----------------------------
102+
## Example
120103

121104
Output of basic example file in example folder, showing basic usage.
122105

123106
![ScreenShot](https://raw.githubusercontent.com/gavinlyonsrepo/bashmultitool/master/documentation/screenshot/example.png)
124107

108+
## Test
109+
110+
The library contains a test section bmtTest used to test library.
111+
The test section contains one function bmtTestFunc which is used to test the library.
112+
The test function is used in the test file "testTest.sh", which runs an semi-automated test on entire library and produces a report. Pass the test file a number between 1-9 , 1-9 correspond to the sections, 0 will test entire library.
113+
The repo also contains a *test folder* where a test file used in development are available, one function for each library file.
114+
115+
```sh
116+
# testTest.sh [section number]
117+
testTest.sh 0
118+
```
119+
125120
Output report of test script testTest.sh.
126121

127122
![ScreenShot](https://raw.githubusercontent.com/gavinlyonsrepo/bashmultitool/master/documentation/screenshot/test.png)

documentation/bmtData.md

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1+
# Data Section
12

23
| Library file | Function | Sections | Content | help file |
34
| ---- | ---- | ---- | ---- | ---- |
4-
| bmtData | btmDataFunc | 601-607 | Data related | bmtData.md|
5+
| bmtData | btmDataFunc | 601-607 | Data related | bmtData.md |
56

6-
**Section Six, Data**
7+
## Data section 601-610
78

89
* 601 integer user input check
910
* 602 alphabet user input check
1011
* 603 alphanumeric user input check
1112
* 604 convert string to lowercase
1213
* 605 convert string to uppercase
1314
* 606 trim white space from string
14-
* 607 String Length
15+
* 607 String Length
16+
* 608 Contains string check
17+
* 609 String Replace
18+
* 610 String Reverse
1519

16-
**Sub-Sections**
17-
18-
601) integer input check
20+
### 601 integer input check
1921

2022
Keyword intcheck, first option the item to be checked if integer
2123

@@ -25,7 +27,7 @@ bmtDataFunc intcheck "$age"
2527

2628
Returns 0 for integer , 2 for non integer.
2729

28-
602) Alphanumeric input check
30+
### 602 Alphanumeric input check
2931

3032
Keyword alphanumcheck, first option the item to be checked if Alphanumeric
3133

@@ -35,7 +37,7 @@ bmtDataFunc alphanumcheck "$address"
3537

3638
Returns 0 for alphanumcheck , 2 for non alphanumcheck.
3739

38-
603) alphabet input check
40+
### 603 alphabet input check
3941

4042
Keyword alphacheck) , first option the item to be checked if alphabet
4143

@@ -45,31 +47,72 @@ bmtDataFunc alphacheck "$name"
4547

4648
Returns 0 for alphabet , 2 for non alphabet.
4749

48-
604) convert a string to lowercase
50+
### 604 convert a string to lowercase
4951

5052
```sh
5153
result=$(bmtDataFunc lowercase "TEST")
5254
echo $result
5355
```
5456

55-
605) convert a string to uppercase
57+
### 605 convert a string to uppercase
5658

5759
```sh
5860
result=$(bmtDataFunc upperrcase "test")
5961
echo $result
6062
```
6163

62-
606) trim whitespace from a strin
64+
### 606 trim whitespace from a strin
6365

6466
```sh
6567
result2=$(bmtDataFunc trim " test "
6668
echo $result2
6769
```
6870
69-
607) String Length
71+
### 607 String Length
72+
7073
Returns string length , maximum 249 , 250 is Null string error.
7174
7275
```sh
7376
bmtDataFunc strlen "test string 123" #15
7477
echo $?
7578
```
79+
80+
### 608 Contains string check
81+
82+
Check if string contains a given substring
83+
84+
1. Param $2 is the string to search within
85+
2. Param $3 is the string to search for
86+
3. Returns 1 for missing params, 0 if found, falls through to the function-level return of 2 for not-found.
87+
88+
```sh
89+
bmtDataFunc contains "This is a test string" "test"
90+
```
91+
92+
### 609 replace string
93+
94+
Replace first (or all) occurrences of a pattern in a string; returns result via echo
95+
96+
1. Param $2 is the input string
97+
2. Param $3 is the pattern to replace
98+
3. Param $4 is the replacement string (can be empty to delete)
99+
4. Param $5 is the optional ALL flag; if set to "ALL", all occurrences of the pattern will be replaced, otherwise only the first occurrence is replaced.
100+
5. Returns 1 if Param $2 or Param $3 is missing.
101+
102+
```sh
103+
# replace all occurrences
104+
result4=$(bmtDataFunc strreplace "hello world world" "world" "bash" "ALL")
105+
printf "%s\n" "$result4" # expect: hello bash bash
106+
```
107+
108+
### 610 Reverse a string
109+
110+
Reverse a string, returns result via echo. tool: rev, which is part of util-linux and present on all Linux systems
111+
112+
1. Param $2 is the input string
113+
2. Returns 1 if Param $2 is missing , otherwise returns 0 andthe reversed string via echo.
114+
115+
```sh
116+
result6=$(bmtDataFunc strrev "hello")
117+
printf "%s\n" "$result6" # expect: olleh
118+
```

0 commit comments

Comments
 (0)