2016-08-16 1 views
0

私はAndroidにシェルスクリプトを書いています。 私は、アプリケーションのデータディレクトリの所有者の名前を決定し、それを変数に割り当て、別のディレクトリの所有者(最初のディレクトリのサブディレクトリになる)を最初のディレクトリの所有者に変更する必要があります変数。コマンドの戻り値をbashの別のコマンドにパラメータとして渡すにはどうすればよいですか?

#assign the owner of the com.netflix.mediaclient to $user variable 
user=`su -c "ls -l /data/data | grep com.netflix.mediaclient | cut -f2 -d' '"` 
#change the owner of the shared_prefs directory to the value in $user variable 
su -c 'busybox chown -R '$user:$user' /data/data/com.netflix.mediaclient/shared_prefs' 

2行目の構文のこれと他の多くのバリエーションは機能しません。

#using double quotes 
su -c 'busybox chown -R "$user:$user" /data/data/com.netflix.mediaclient/shared_prefs' 
#using no quotes 
su -c 'busybox chown -R $user:$user /data/data/com.netflix.mediaclient/shared_prefs' 

答えて

1

使用stat所有者を見つけ、'$user:$user'が動作しませんなぜ二重引用符の内側に

user="$(busybox stat -c '%U' /data/data/com.netflix.mediaclient)" 
busybox chown -R "$user:$user" /data/data/com.netflix.mediaclient/shared_prefs 

$user:$userを置きますか?

シングル引用符の中に置かれたものはすべて、文字通りbashによって取り込まれ、変数の展開は行われません。

+0

アンドロイドシェルのstatコマンドに-cスイッチがないようです。ビジーボックスのバイナリでさえない – PrashanD

+0

@Prashan: '-c switch'が見つからないかもしれないが、'ビジーボックスのバイナリでさえない 'という意味はどういう意味ですか? – sjsam

+0

私はstatコマンドのbusybox版に-cスイッチも持たないことを意味しました。 (つまり、busybox stat -c '%U' /data/data/com.netflix.mediaclientは動作しません)。しかし、問題は、2番目のコマンドの構文ではないですか?最初のコマンドを修正しても影響はありません。 – PrashanD

関連する問題