将bash脚本转换为busybox脚本

将bash脚本转换为busybox脚本,bash,curl,embedded,busybox,ash,Bash,Curl,Embedded,Busybox,Ash,我正在开发一个只有busybox(ash?)且不支持bash的设备。但是,我需要在上面运行下面的bash脚本。是可能的还是busybox根本不支持脚本 #!/bin/bash domain="mydomain.com" record="11019653" api_key="key1234" ip="$(curl http://ipecho.net/plain)" echo content="$(curl \ -k \ -H "Authorization: Bearer $a

我正在开发一个只有busybox(ash?)且不支持bash的设备。但是,我需要在上面运行下面的bash脚本。是可能的还是busybox根本不支持脚本

#!/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")"

您的脚本中没有任何问题可能会崩溃

好吧,除了你在做
echo content=“…”
。将在输出中打印单词
content=
,该单词以引号形式连接到命令的输出

如果要设置变量的值,然后打印它,请执行以下操作:

#!/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"
如果与名称ash链接,程序busybox将充当shell:

ln -s /bin/busybox /bin/ash
即使在当前目录(或测试目录)中:


然后,如果在PWD中键入
/ash
,或者如果在PATH目录中键入
ash
,就可以启动它。如果愿意,您可以从中测试命令和脚本,或者使用bash作为shell,使用
ash script.sh
或(更好的)
/script.sh
启动脚本,如果文件的she bang是
#/bin/ash

您的脚本中没有可能在ash中中断的问题

好吧,除了你在做
echo content=“…”
。将在输出中打印单词
content=
,该单词以引号形式连接到命令的输出

如果要设置变量的值,然后打印它,请执行以下操作:

#!/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"
如果与名称ash链接,程序busybox将充当shell:

ln -s /bin/busybox /bin/ash
即使在当前目录(或测试目录)中:

然后,如果在PWD中键入
/ash
,或者如果在PATH目录中键入
ash
,就可以启动它。如果愿意,您可以从中测试命令和脚本,或者使用bash作为shell,使用
ash script.sh
或(更好的)
/script.sh
启动脚本,如果文件的she bang是
#/垃圾箱/灰烬