大佬教程收集整理的这篇文章主要介绍了如何在 bash,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
对于涉及通过 ADB sHell 作为用户 ceres 发出 dconf 命令的 bash 脚本,我需要嵌套多个命令。 以下三个命令的手动顺序执行完美无缺。
adb sHell su ceres dconf write /desktop/asteroID/watchface "'file:///usr/share/asteroID-launcher/watchfaces/$opt.qml'"
@H_419_5@我学会了转义 dconf 关键字以在
su ceres -c '<command>'
中正确嵌套 dconf。su ceres -c 'dconf write /desktop/asteroID/watchface \"'file:///usr/share/asteroID-launcher/watchfaces/$opt.qml'\"'
@H_419_5@如何将上面的命令嵌套并转义到
adb sHell "<command>"
中?adb sHell "su ceres -c 'dconf write /desktop/asteroID/watchface \"'file:///usr/share/asteroID-launcher/watchfaces/$opt.qml'\"'"
@H_419_5@当从 bash 脚本发出时,导致 dconf 回复
error: 0-4:unkNown keyword
。感谢您的帮助和解释!
解决方法
对于极度嵌套的情况,我会坚持使用
printf %q
而不是手动引用:,#! /usr/bin/env bash printf -v cmd %q "'file:///usr/share/asteroid-launcher/watchfaces/$opt.qml'" printf -v cmd %q "dconf write /desktop/asteroid/watchface $cmd" adb sHell "su ceres -c $cmd"
据推测,
adb sHell
从标准输入读取。您可以使用此处的文档来简化此操作(以及使用sudo
执行adb sHell
而不是使用su
):sudo -u ceres adb sHell <<EOF dconf write /desktop/asteroid/watchface "file:///usr/share/asteroid-launcher/watchfaces/$opt.qml" EOF
如果没有,这可能会更简单,
sudo -u ceres adb sHell -c "dconf write /desktop/asteroid/watchface 'file:///usr/share/asteroid-launcher/watchfaces/$opt.qml'"
以上是大佬教程为你收集整理的如何在 bash全部内容,希望文章能够帮你解决如何在 bash所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。