一重引用符と二重引用符コマンドで$変数を使用する方法

一重引用符と二重引用符コマンドで$変数を使用する方法

次の内容を含むbashスクリプトがあります。

USERLIST="/tmp/adusers.list.names.only.txt"
cat $USERLIST | while read users
do
num=$[$num+1]
USR=`echo $users | awk '{print $1}'`
STATUS=`winexe -U DC/ID%"PASS" //10.0.0.1 'powershell.exe -command "import-module activedirectory; Get-ADUser $USR -Properties * | select Enabled"'`
echo "$USR : $STATUS"
done

ただし、このコマンドはユーザー名を取得する代わりに$USR変数を表示します。

winexe -U DC/ID%"PASS" //10.0.0.1 'powershell.exe -command "import-module activedirectory; Get-ADUser $USR -Properties * | select Enabled"'

二重引用符を試しましたが、うまくいきませ"$VAR"んでした。

ベストアンサー1

呼び出し$USRに出てくる部分が一重引用符( )の中で変数winexeに変換されていないようです。'

行を変更して試してください。

STATUS=`winexe -U DC/ID%"PASS" //10.0.0.1 'powershell.exe -command "import-module activedirectory; Get-ADUser $USR -Properties * | select Enabled"'`

入力する

STATUS=`winexe -U DC/ID%"PASS" //10.0.0.1 'powershell.exe -command "import-module activedirectory; Get-ADUser '"$USR"' -Properties * | select Enabled"'`

一重引用符をエスケープするには、二重引用符を入力して変数値を挿入します。

おすすめ記事