0

スクリプトを使用して null 文字列を渡す方法。agqmi start 0 "" "" "" として。プロファイル ファイルで設定が見つからない場合。また、アプリケーションはスクリプトを介して呼び出していません。ただし、コマンドラインを介して機能します(agqmi start 0 "" "" "")。

profile_file

APN='airtelgprs.com'

USR='username'

PASS='password'

PAPCHAP='2'



if [ -f "$PROFILE_FILE" ]; then                                       

 echo "Loading profile..." >>$LOG                                

PAPCHAP=`cat agqmi-network.conf | grep 'PAPCHAP' | awk '{print $1}' | cut -f2 

-d"'"`                                                                                           
APN=`cat agqmi-network.conf | grep 'APN' | awk '{print $1}' | cut -f2 -d"'"`

USR=`cat agqmi-network.conf | grep 'USR' | awk '{print $1}' | cut -f2 -d"'"`

PASS=`cat agqmi-network.conf | grep 'PASS' | awk '{print $1}' | cut -f2 -d"'"`


if [ "x$PAPCHAP" == "x" ]; then
PAPCHAP="0"
fi

if [ "x$APN" == "x" ]; then
APN="\"\""
fi

if [ "x$USR" == "x" ]; then
USR="\"\"" 
fi

if [ "x$PASS" == "x" ]; then
PASS="\"\""                                                                                     
fi                                                                                                      

fi

私は実行しようとしました

    STATUS_CMD="./agqmi start "$PAPCHAP" "$APN" "$USR" "$PASS""    
    echo "$STATUS_CMD" >>$LOG                                                      
    `$STATUS_CMD`
4

2 に答える 2

1

最初に保存する方法でコマンドを実行する方法は、次のとおりです (配列を使用)。

STATUS_CMD=(./agqmi start "$PAPCHAP" "$APN" "$USR" "$PASS")
echo "${STATUS_CMD[*]}" >>$LOG
"${STATUS_CMD[@]}"

を使用することもできevalますが、変数の値によっては誤って解釈される可能性があります。

""また、空であることを意図した変数を(リテラル)に再割り当てする必要はおそらくないでしょう。に変換する必要があるもののみ0:

if [ "x$PAPCHAP" == "x" ]; then
    PAPCHAP="0"
fi
#if [ "x$APN" == "x" ]; then
#    APN="\"\""
#fi
#if [ "x$USR" == "x" ]; then
#    USR="\"\""
#fi
#if [ "x$PASS" == "x" ]; then
#    PASS="\"\""
#fi

また、比較には のようなマーカーは必要ありませんx。使用[[ ]]もおすすめです。

if [[ $PAPCHAP == '' ]]; then  ## Or simply [[ -z $PAPCHAP ]]
    PAPCHAP=0
fi

POSIX の更新:

if [ -z "$PAPCHAP" ]; then
    PAPCHAP=0
fi
#if [ -z "$APN" ]; then
#    APN=''
#fi
#if [ -z "$USR" ]; then
#    USR=''
#fi
#if [ -z "$PASS" ]; then
#    PASS=''
#fi

STATUS_CMD="./agqmi start \"$PAPCHAP\" \"$APN\" \"$USR\" \"$PASS\""
echo "$STATUS_CMD" >>"$LOG"
./agqmi start "$PAPCHAP" "$APN" "$USR" "$PASS"  ## Just execute it directly and not inside a variable.

そして多分あなたは追加すべきではありません./か?

STATUS_CMD="agqmi start \"$PAPCHAP\" \"$APN\" \"$USR\" \"$PASS\""
echo "$STATUS_CMD" >>"$LOG"
agqmi start "$PAPCHAP" "$APN" "$USR" "$PASS"

とにかく、実際には変数に格納する必要はありません。

echo "agqmi start \"$PAPCHAP\" \"$APN\" \"$USR\" \"$PASS\"" >>"$LOG"
agqmi start "$PAPCHAP" "$APN" "$USR" "$PASS"
于 2013-09-09T09:56:42.250 に答える
0

パラメータとして「\0」を渡してみましたか?

私はsolarisサーバーを持っていて、パラメータとしてNULL文字列を渡す必要があるときはいつでも「\0」を使用しています。

あなたのコマンドは次のようになります

agqmi start 0 "\0" "\0" "\0"

それがあなたのために働くかどうか私に知らせてください。

于 2013-09-09T13:07:28.983 に答える