-1
I am new to Shell Scripts and not aware of the syntax.

Android デバイスにプッシュし、「busybox dos2unix」で変換するシェル スクリプトがあります。

adb shell busybox dos2unix /data/local/myShellScript.sh

スクリプトでは、文字列が空かどうかをチェックしようとしていますか? しかし、エラーが発生しています: 'unexpected operator/operand' .

以下は私のコードです:

echo "Getting a PID (Process ID) from a file" ;
pid=`cat  /sdcard/PIDofTask.txt` ;
echo "PID of task is : " $pid ;
echo "Checking if the pid exists, to verify the process is running" ;    
pidString=$(ps | grep ${pid}) ;
echo "PID string : " $pidString ;

if [ $pidString ] ;
then
    echo "pid String is not empty" ;
else 
    echo "pid String is empty" ;
fi ;

出力:

Getting a PID (Process ID) from a file
PID of task is : 11571
Checking if the pid exists, to verify the process is running
PID string : root 11571 8082 4180 1828 poll_sched 7faa42dcdc S sh
/data/local/myShellScript.sh[2]: [: 11571: unexpected operator/operand
pid String is empty

[ -n $pidString ] と [ -z $pidString ] オプションも試しました。しかし、どちらもエラーを出しています。

私はどこで間違いを犯していますか?助けてくれて本当にありがとう...

4

2 に答える 2

1

空の文字列を確認するには、-z を使用する必要があります。

例:

if [ -z "$str" ] ;
于 2016-02-05T06:34:58.010 に答える