You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

@renault-digital/bash-base

Package Overview
Dependencies
Maintainers
2
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@renault-digital/bash-base - npm Package Compare versions

Comparing version

to
1.2.1

docs/help.gif

2

CHANGELOG.md

@@ -0,1 +1,3 @@

## [1.2.1](https://github.com/renault-digital/bash-base/compare/v1.2.0...v1.2.1) (2020-09-11)
# [1.2.0](https://github.com/renault-digital/bash-base/compare/v1.1.1...v1.2.0) (2020-09-10)

@@ -2,0 +4,0 @@

2

package.json
{
"name": "@renault-digital/bash-base",
"version": "1.2.0",
"version": "1.2.1",
"description": "A common lib for creating bash script easily.",

@@ -5,0 +5,0 @@ "private": false,

@@ -15,141 +15,37 @@ # Welcome to [bash-base](https://renault-digital.github.io/bash-base)

## What's bash-base?
## Goal
A common lib for creating bash script easily like other program language.
No more spending time searching the special ways of bash for basic operations like "how to replace a string in bash", then compare, choose, and test among many potential solutions.
- Rich functions to operate array/list/set/string/arguments/reflect/..., the functions can be used in console or script
- Just call bash-base function by name in your script, like other programing language, no need anymore to search "how to ... in bash"
- Parse and validation arguments easily & flexible, automatically generate help usage for your script, focus your script only on the business logical
- Make your script more compact & readability
- Available on github/npm/dockerhub
Bash-base does this for you, you can just call the function here which is well tested and stable, and only focus you on the high level logic. Writing your script with less time, but more readability.
![bash-base.gif](bash-base.gif)
## Quick start
## Latest Update
See [CHANGELOG.md](CHANGELOG.md)
```shell
#!/usr/bin/env bash
source <(docker run renaultdigital/bash-base)
## How to use
SHORT_DESC='an example shell script to show how to use bash-base '
#### 1. Install from docker
args_parse $# "$@" firstName age sex country
args_valid_or_read firstName '^[A-Za-z ]{2,}$' "Your first name (only letters)"
args_valid_or_read age '^[0-9]{1,2}$' "Your age (maxim 2 digits))"
args_valid_or_select_pipe sex 'Mr.|Mrs' "Your sex"
See [docker hub](https://hub.docker.com/r/renaultdigital/bash-base)
response=$(curl -sS 'https://restcountries.eu/rest/v2/regionalbloc/eu' --compressed)
string_pick_to_array '{"name":"' '","topLevelDomain' countryNames "$response"
args_valid_or_select country countryNames "Which country"
print_success "Hello $sex $(string_upper_first "$firstName"), you are in $country, and your age is $age, nice to meet you."
```
source <(docker run --rm renaultdigital/bash-base)
```
Or specific a fixed version
Generated help usage:
![help.gif](docs/help.gif)
```
source <(docker run --rm renaultdigital/bash-base:1.0.2)
```
Run it:
![run.gif](docs/run.gif)
Available on github, npm and dockerhub, see [other ways of usage](docs/USAGE.md).
#### 2. Install from NPM
See [npm repackage](https://www.npmjs.com/package/@renault-digital/bash-base)
```
npm i -g @renault-digital/bash-base
```
verify the installation
```
man bash-base
```
or one line in your script:
```
# import, and install bash-base from npmjs only if not installed:
source bash-base 2>/dev/null || npm i -g @renault-digital/bash-base && source bash-base
```
To uninstall:
```
npm uninstall -g @renault-digital/bash-base
```
#### 3. Install from GitHub
The directory installed is `~/.bash-base`.
##### install if not existed the specific version in console / shell script:
- the man page of version v1.0.2: `man bash-base.v1.0.2`,
- you can import this version in one line in your script:
```
source bash-base.v1.0.2 2>/dev/null || curl -o- -L https://raw.githubusercontent.com/renault-digital/bash-base/master/scripts/install.sh | bash -s -- v1.0.2"
```
##### If you always prefer to use the latest version, install if not existed the latest version in console / shell script:
- the man page is: `man bash-base`,
- and import like this:
```
source bash-base 2>/dev/null || curl -o- -L https://raw.githubusercontent.com/renault-digital/bash-base/master/scripts/install.sh | bash
```
or
```
source bash-base 2>/dev/null || curl -o- -L https://raw.githubusercontent.com/renault-digital/bash-base/master/scripts/install.sh | bash -s -- latest
```
###### Notes:
this way, your script will access github to check whether a newer version published during every time it launched.
if you don't like this behavior, you need to specify a fixed version to use in your script.
##### If you want to check all functions of bash-base is compatible with your environment when install, using param `verify` :
```
source bash-base 2>/dev/null || curl -o- -L https://raw.githubusercontent.com/renault-digital/bash-base/master/scripts/install.sh | bash -s -- latest verify
```
or
```
source bash-base 2>/dev/null || curl -o- -L https://raw.githubusercontent.com/renault-digital/bash-base/master/scripts/install.sh | bash -s -- v1.0.2 verify
```
##### To uninstall all versions of bash-base from your system:
```
curl -o- -L https://raw.githubusercontent.com/renault-digital/bash-base/master/scripts/install.sh | bash -s -- uninstall
```
#### 4. Import bash-base from GitHub when execute
Simply write in console or script:
If to import latest version:
```
source <(curl -fsSL https://raw.githubusercontent.com/renault-digital/bash-base/master/bin/bash-base.sh)
```
or
```
eval "$(curl -fsSL https://raw.githubusercontent.com/renault-digital/bash-base/master/bin/bash-base.sh)"
```
If to import specific version:
```
source <(curl -fsSL https://raw.githubusercontent.com/renault-digital/bash-base/v1.0.2/bin/bash-base.sh)
```
or
```
eval "$(curl -fsSL https://raw.githubusercontent.com/renault-digital/bash-base/v1.0.2/bin/bash-base.sh)
```
Verify the import in console:
```
string_trim ' hello '
```
###### Notes
this way, your script need to access github when each time it launched.
#### 5. Download only
download a specific version:
- from NPM: https://registry.npmjs.org/@renault-digital/bash-base/-/bash-base-1.0.2.tgz
- from github: https://github.com/renault-digital/bash-base/archive/v1.0.2.tar.gz
## Example

@@ -164,2 +60,5 @@ See [example](example) folder

## Latest Update
See [CHANGELOG.md](CHANGELOG.md)
## Contributing

@@ -166,0 +65,0 @@ See [How to contribute](CONTRIBUTING.md)

Sorry, the diff of this file is too big to display