# プロジェクトに移動
$ cd /path/to/your/project
# bin ディレクトリを作成して bin に移動
$ cd mkdir bin
$ cd bin
# ファイルを作成
$ touch var
$ touch test
# 権限変更
$ chmod 744 var
$ chmod 744 test
var (.sh)
#!/bin/sh
SAMPLE_USER="user"
SAMPLE_PASSWORD="password"
test (.sh)
#!/bin/sh
cd `dirname $0`
d=`pwd`
source $d/var
echo $SAMPLE_USER
echo $SAMPLE_PASSWORD
実行
$ cd /path/to/your/project
$ bin/test
user
password
source: not found エラーが出た場合
AI による概要
source: not found エラーは、スクリプトの実行に sh が使われていることが原因です。source は bash の組み込みコマンドであり、標準の sh(Ubuntuなどの /bin/sh)には存在しません。解決方法
スクリプト内の source コマンドをドット . に変更する
(例: source ~/.bashrc を . ~/.bashrc にする)。
だそう。
test (.sh)
source $d/var
の部分を、
. $d/var
に変更する。