| Both sides previous revision Previous revision | |
| docs:guide-developer:write-shell-script [2020/08/10 18:20] – [Write shell scripts in OpenWrt] - changed link to bash project to point version independent URL dadillac | docs:guide-developer:write-shell-script [2020/08/10 18:24] (current) – [Write shell scripts in OpenWrt] - Added headers to make content clearer dadillac |
|---|
| ====== Write shell scripts in OpenWrt ====== | ====== Write shell scripts in OpenWrt ====== |
| | |
| | ===== The default OpenWrt shell is ash: the Almquist shell ===== |
| | |
| The default [[wp>Command-line_interface|shell]] provided with //OpenWrt// is the [[wp>Almquist_shell|Almquist shell]], which is better known as the //ash shell// and is also the default [[wp>BusyBox|Busybox]] shell. Most [[wp>Linux_distribution|Linux distros]], such as [[wp>Ubuntu|Ubuntu]] or [[wp>Debian|Debian]], will use the [[wp>Bash_(Unix_shell)|Bash]] shell, which is much bigger and more complex than //ash//. For example, a typical //bash// implementation requires approximately 1 MB of disk space, which is an extravagant waste of memory/space in an embedded device. | The default [[wp>Command-line_interface|shell]] provided with //OpenWrt// is the [[wp>Almquist_shell|Almquist shell]], which is better known as the //ash shell// and is also the default [[wp>BusyBox|Busybox]] shell. Most [[wp>Linux_distribution|Linux distros]], such as [[wp>Ubuntu|Ubuntu]] or [[wp>Debian|Debian]], will use the [[wp>Bash_(Unix_shell)|Bash]] shell, which is much bigger and more complex than //ash//. For example, a typical //bash// implementation requires approximately 1 MB of disk space, which is an extravagant waste of memory/space in an embedded device. |
| |
| By contrast, //BusyBox// fits in less than 512 KB of space, and, in addition to providing the //ash// shell, it also provides many other tools you will need to manage your OpenWrt device. Some examples of the other very useful tools provided by //BusyBox// include [[wp>AWK|awk]], [[wp>grep|grep]], [[wp>sed|sed]], and [[https://en.wikibooks.org/wiki/Learning_the_vi_Editor/BusyBox_vi|vi/vim]]. Note that the stock (//i.e.// factory) firmware that ships with many routers also uses //BusyBox// for the reasons outlined here. | By contrast, //BusyBox// fits in less than 512 KB of space, and, in addition to providing the //ash// shell, it also provides many other tools you will need to manage your OpenWrt device. Some examples of the other very useful tools provided by //BusyBox// include [[wp>AWK|awk]], [[wp>grep|grep]], [[wp>sed|sed]], and [[https://en.wikibooks.org/wiki/Learning_the_vi_Editor/BusyBox_vi|vi/vim]]. Note that the stock (//i.e.// factory) firmware that ships with many routers also uses //BusyBox// for the reasons outlined here. |
| | |
| | ===== OpenWrt, BusyBox, and the ash shell ===== |
| |
| OpenWrt firmware uses [[wp>Busybox|BusyBox]] because it is extremely efficient with respect to 1) the size required to install it and run it in RAM, and 2) the amount of functionality it provides. Please be aware that many of the //BusyBox// implementations of common Linux/Unix tools might be more limited than their full desktop counterparts. However, //Bash// and //Busybox// shell are similar enough for the majority of daily use cases. If your script is using the [[wp>POSIX|POSIX]] features of the //Bash// shell, then it will work in the //Ash// shell, too. | OpenWrt firmware uses [[wp>Busybox|BusyBox]] because it is extremely efficient with respect to 1) the size required to install it and run it in RAM, and 2) the amount of functionality it provides. Please be aware that many of the //BusyBox// implementations of common Linux/Unix tools might be more limited than their full desktop counterparts. However, //Bash// and //Busybox// shell are similar enough for the majority of daily use cases. If your script is using the [[wp>POSIX|POSIX]] features of the //Bash// shell, then it will work in the //Ash// shell, too. |