打开一个bash脚本到busybox的脚本 [英] Turning a bash script into a busybox script

查看:1355
本文介绍了打开一个bash脚本到busybox的脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作,只有具有busybox的(灰?),不支持bash的设备上。不过,我需要在其上运行下面的bash脚本。是否有可能或busybox的根本不支持脚本?

 #!/斌/庆典域=mydomain.com
记录=11019653
API_KEY =key1234IP =$(卷曲http://ipecho.net/plain)回声内容=$(卷曲\\
    -k \\
    -H授权:承载$ API_KEY\\
    -H内容类型:应用程序/ JSON\\
    -d{数据:'$ IP'}'\\
    -X PUThttps://api.digitalocean.com/v2/domains/$domain/records/$record)


解决方案

有是在脚本中没有任何问题,可以在灰打破。

好了,除非你正在做的回声内容=...。这将在输出打印的字内容= 加入到命令的引号中的输出。

如果你想设置一个变量的值,然后打印出来,这样做:

 #!/ bin中/灰域=mydomain.com
记录=11019653
API_KEY =key1234IP =$(卷曲http://ipecho.net/plain)内容=$(卷曲\\
-k \\
-H授权:承载$ API_KEY\\
-H内容类型:应用程序/ JSON\\
-d{数据:'$ IP'}'\\
-X PUThttps://api.digitalocean.com/v2/domains/$domain/record/$record)回声$内容

该计划的busybox将作为外壳名字由灰联行动:

  LN -s /斌/ busybox的/ bin中/灰

甚至在你的present目录(或测试一个):

  LN -s /斌/ Busybox的ash

然后,您可以通过键入启动 ./灰分如果在PWD,或灰分如果在一个PATH目录。如果你愿意,你可以从中测试命令和脚本,或者使用bash作为你的shell,并开始与灰script.sh 或脚本(更好)。 /script.sh 如果该文件的她,爆炸是#!/ bin中/灰

I am working on a device that only has busybox (ash?) and does not support bash. However, I need to run the bash script below on it. Is it possible or busybox simply does not support scripts?

#!/bin/bash

domain="mydomain.com"
record="11019653"
api_key="key1234"

ip="$(curl http://ipecho.net/plain)"

echo content="$(curl \
    -k \
    -H "Authorization: Bearer $api_key" \
    -H "Content-Type: application/json" \
    -d '{"data": "'"$ip"'"}' \
    -X PUT "https://api.digitalocean.com/v2/domains/$domain/records/$record")"

解决方案

There is no issue in your script that could break in ash.

Well, except that you are doing echo content="....". That will print in the output the word content= joined to the output of the command in quotes.

If you want to set the value of a variable and then print it, do:

#!/bin/ash

domain="mydomain.com"
record="11019653"
api_key="key1234"

ip="$(curl http://ipecho.net/plain)"

content="$(curl \
-k \
-H "Authorization: Bearer $api_key" \
-H "Content-Type: application/json" \
-d '{"data": "'"$ip"'"}' \
-X PUT "https://api.digitalocean.com/v2/domains/$domain/record/$record")"

echo "$content"

The program busybox will act as a shell if linked with the name ash:

ln -s /bin/busybox /bin/ash

Even in your present directory (or a test one):

ln -s /bin/busybox ash

Then, you could start it by typing ./ash if in the PWD, or ash if in a PATH directory. You could test commands and scripts from it if you wish, or use bash as your shell and start scripts with ash script.sh or (better) ./script.sh if the she-bang of the file is #!/bin/ash

这篇关于打开一个bash脚本到busybox的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆