1
1

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.

shellで空白を含む実行するスクリプトを配列に格納

Posted at

shellでunit testを書こうと思ったがFixtureの様な仕組みが作れなかったので、とりあえず暫定での対応方法を考え中。
後からいいのが思いついたら試してみる

文字列化 -> 後で除く


# !/bin/bash

function main() {
	local -a _arr=()
	local _func1="print_str hello"
	local _func2="print_str world"
	local _func3="print_str !"
	_arr+=("'\${_func1}'")
	_arr+=("'\${_func2}'")
	_arr+=("'\${_func3}'")

	for _func in ${_arr[@]}
	do
		echo "eval ${_func}"
		eval `echo ${_func} | tr -d "'"`
	done
}

function print_str() {
	local _str="${1}"
	echo "${_str}"
}

main

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?