26
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Posted at

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が読みやすくなりますね。

26
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?