Help us understand the problem. What is going on with this article?

Bashで便利なフレームワーク

More than 3 years have passed since last update.

bash-oo-framework(Bash Infinity)というものがあります。

ShellScriptを書くときは、これが便利になることがあります。

Bashでフレームワークを使うこと自体にはあまり意味があるとは思えませんが(Bashは速度及び、環境にあまり左右されず使えるため)、しかし、ShellScriptの可読性は向上すると思われます。

$ bash
$ which bash
/usr/local/bin/bash
$ git clone https://github.com/niieani/bash-oo-framework
$ cd bash-oo-framework
$ vim your-script.sh

基本的にはlibフォルダの上にスクリプトを置けば動作します。exampleフォルダを参考にしながら使い方を理解します。

bash-oo-framework/your-script.sh
#!/usr/local/bin/bash

source "$( cd "${BASH_SOURCE[0]%/*}" && pwd )/lib/oo-bootstrap.sh"

import util/log util/type
Log::AddOutput util/type CUSTOM

passingArrays() {
  passingArraysInput() {
    [array] passedInArray
    $var:passedInArray push 'will work only for references'
    $var:passedInArray push 'test'
  }

  array someArray=( 'one' 'two' )
  passingArraysInput $ref:someArray
  $var:someArray toJSON
}

passingArrays
$ ./your-script.sh
["one", "two", "will work only for references", "test"]

これで少しはShell Scriptが読みやすくなりますね。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした