2017-05-03 13 views
2

コンテキスト:バッシュエラー「コマンドが見つかりません」

私はbashで変数に格納されているコマンドを実行します。

マイbashのファイル:

#!/bin/bash 
# ----------------------------------------------- 
# ---    COMMANDS     --- 
# ---    Vanilla style    --- 
# ----------------------------------------------- 
GRUNT="node_modules/grunt-cli/bin/grunt" 
LS="ls" 
# ----------------------------------------------- 
# ---    COMMANDS     --- 
# ---    Using Docker    --- 
# ----------------------------------------------- 
GRUNT="docker exec compose_custom-node_1 node_modules/grunt-cli/bin/grunt" 
LS="docker exec compose_custom-node_1 ls" 


# *********************************************** 
# ***    Execution    *** 
# *********************************************** 
# ----------------------------------------------- 
# Compile SCSS using Grunt 
# ----------------------------------------------- 
echo "Building CSS from Sass files..." 
echo "$(docker exec compose_custom-node_1 ls -l)" 
echo "$($LS -l)" 
$($GRUNT sass) 

問題:私はこのbashのファイルを実行すると

grunt sassコマンドはエラーをスロー:

mybash.sh: line 25: $'\E[4mRunning' : command not found

私はbashの全体のリターン:

[email protected]:/var/www/my_folder$ ./my_bash.sh 
Building CSS from Sass files... 
total 188 
-rw-rw-r-- 1 node node 3627 May 2 19:00 Gruntfile.js 
drwxr-xr-x 282 root root 12288 May 3 12:12 node_modules 
drwxr-xr-x 4 node node 4096 May 2 18:39 sass 
total 188 
-rw-rw-r-- 1 node node 3627 May 2 19:00 Gruntfile.js 
drwxr-xr-x 282 root root 12288 May 3 12:12 node_modules 
drwxr-xr-x 4 node node 4096 May 2 18:39 sass 
my_bash.sh: ligne 25: $'\E[4mRunning' : commande introuvable 

調査:

echo "$(docker exec compose_custom-node_1 ls -l)"echo "$($LS -l)"が動作するように見えるのコマンドではなく、$($GRUNT sass)

私はターミナルでdocker exec compose_custom-node_1 node_modules/grunt-cli/bin/gruntを実行する場合、私はこの出力を参照してください。

Running "sass:app1" (sass) task 
Running "sass:sticky-app2" (sass) task 
Done, without errors. 

質問:

あなたは私のための手がかりを持っていますか?私が間違っていることは何ですか?変数より複雑なコマンドを格納するための機能を使用することをお勧め

+0

ターミナルで 'docker exec compose_custom-node_1 node_modules/grunt-cli/bin/grunt sass'を実行するとどうなりますか?あなたの問題コマンドが実行されているようです。 – arco444

+0

@ arco444 'docker exec compose_custom-node_1 node_modules/grunt-cli/bin/grunt'を実行しているのと同じです。 – darckcrystale

+2

このタイプの質問はよくhttp://mywiki.wooledgeを参照してください。 org/BashFAQ/050 –

答えて

4

grunt() { 
    docker exec compose_custom-node_1 node_modules/grunt-cli/bin/grunt "[email protected]" 
} 

とスクリプトに必要な場所だけ

grunt "saas" 

としてこれを呼び出します。複雑な場合のこの正確な要件については、BashFAQ-050を参照してください。

+0

私の場合、 'GRASS'コマンドにパラメータを追加する必要があります:' sass'。どのように関数の作成でこれを行うには? – darckcrystale

+2

@darckcrystale:単純な、引数を渡すだけです – Inian

関連する問題