コマンドエラーの検索(cygwin)

コマンドエラーの検索(cygwin)

次のスクリプトがあります。

#!/bin/bash

cd "/cygdrive/d/apple1/"
_pwd=`pwd`
_find=`find \"$_pwd\" -maxdepth 1 -type d | wc -l`
echo "command: find \"$_pwd\" -maxdepth 1 -type d | wc -l"
echo "find: $_find"
if [ "$_find" -gt 1 ]; then
    echo ""
fi

これはスクリプト出力です

user@my-laptop ~/scripts
$ ./jltest.sh
command: find "/cygdrive/d/apple1" -maxdepth 1 -type d | wc -l
find:
./jltest.sh: line 9: [: : integer expression expected

user@my-laptop ~/scripts
$ find "/cygdrive/d/apple1" -maxdepth 1 -type d | wc -l
3

最初のコマンドが示すように、「予測整数式」エラーが発生します。しかし、手動でコマンドを実行し、番号3を取得します。

なぜこれが起こるのかご存知ですか?

これが私の "apple1"フォルダの内容です。

user@my-laptop ~/scripts
$ ls -la /cygdrive/d/apple1/
total 4
drwxrwx---+ 1 user None   0 May  3 13:11 .
drwxrwx---+ 1 SYSTEM SYSTEM 0 May  3 13:11 ..
drwxrwx---+ 1 user None   0 May  3 13:11 apple11
drwxrwx---+ 1 user None   0 May  3 13:11 apple12

cygwinは実際にはnixではないので、これがこのスタック交換セクションに収まるかどうかはわかりません。しかし、ここでより多くの答えが得られることを願っています。また、まだ初期ベータ版のWindows 10モジュール「Linux for Windows」を試してみました。

ベストアンサー1

問題のラインです。印刷するときは引用符をエスケープする必要がありますが、実行するときはエスケープする必要があります。

_find=`find "$_pwd" -maxdepth 1 -type d | wc -l`

おすすめ記事