2017-07-17 12 views
0

私は次のスクリプトを手元に持っていますが、エラーはあると思いますが、問題は、スクリプトは何も返さないが、スペルミスの単語を返すことになっているということです。私は、このコマンドを使用して、このスクリプトを実行私はaspellを使用してスペルチェックファイルをチェックするbashスクリプトを作成しようとしています

$ sh ./action.sh "{\"b64\":\"`base64 input.txt`\" }" 

INPUT.TXT持っ6つのワード: 猫犬 elephentライオン moooseバグ

、それは

{ "result": "" } 

を返しますが、私はそれを返すようにしたいです

{ "result": "elephent mooose " } 

#!/bin/bash 
# 
# This script expects one argument, a String representation of a JSON 
# object with a single attribute called b64. The script decodes 
# the b64 value to a file, and then pipes it to aspell to check spelling. 
# Finally it returns the result in a JSON object with an attribute called 
# result 
# 
FILE=/home/user/output.txt 

# Parse the JSON input ($1) to extract the value of the 'b64' attribute, 
# then decode it from base64 format, and dump the result to a file. 
echo $1 | sed -e 's/b64.://g' \ 
     | tr -d '"' | tr -d ' ' | tr -d '}' | tr -d '{' \ 
     | base64 --decode >&2 $FILE 

# Pipe the input file to aspell, and then format the result on one line with 
# spaces as delimiters 
RESULT=`cat $FILE | aspell list | tr '\n' ' ' ` 

# Return a JSON object with a single attribute 'result' 
echo "{ \"result\": \"$RESULT\" }" 
+0

のbash -xを使用してスクリプトを実行します。これは、変数RESULTの変更をよりよく追跡するのに役立ちます。 –

+0

私はSHとしてみてください、それはファイルを出力し-x = /ホーム/フセイン/ output.txtと +エコー{ "B64": "Q2F0IGRvZyAKZWxlcGhhbnQgbGlvbgptb29zZSBidWcK"} + SED -es/B64://グラム + TR -d " + TR -d + TR -d} + TR -d { + base64で--decode /home/huseyin/output.txt +猫+ のaspellリスト+ /home/huseyin/output.txt TR \ n + RESULT = + echo {"result": ""} {"result": ""} –

答えて

0

I tヒンク、問題はリダイレクトです。私は>&2 $FILE> $FILE 2>&1 に変更しました。 (最初のものはOKではない理由を私は知らない)

ここでは、出力されます。

[email protected]:/tmp$ sh ./action.sh "{\"b64\":\"`base64 input.txt`\" }" 
{ "result": "elephent mooose " } 

コード:

#!/bin/bash 
# 
# This script expects one argument, a String representation of a JSON 
# object with a single attribute called b64. The script decodes 
# the b64 value to a file, and then pipes it to aspell to check spelling. 
# Finally it returns the result in a JSON object with an attribute called 
# result 
# 
FILE=/tmp/output.txt 

# Parse the JSON input ($1) to extract the value of the 'b64' attribute, 
# then decode it from base64 format, and dump the result to a file. 
echo $1 | sed -e 's/b64.://g' \ 
     | tr -d '"' | tr -d ' ' | tr -d '}' | tr -d '{' \ 
     | base64 --decode > $FILE 2>&1 

# Pipe the input file to aspell, and then format the result on one line with 
# spaces as delimiters 
RESULT=`cat $FILE | aspell list | tr '\n' ' ' ` 

# Return a JSON object with a single attribute 'result' 
echo "{ \"result\": \"$RESULT\" }" 
+0

答えのおかげで、空の出力ファイルを読み込んでいたと思います。すべてが間違っています。 –

関連する問題