User Tools

Site Tools


Write shell scripts in OpenWrt

The default shell in OpenWrt is Ash, the Busybox default shell. Most Linux distros like Ubuntu or Debian will use Bash, which is much bigger and more complex (it's around 1 MB). OpenWrt and stock firmware of routers will use Busybox which is very very light and can fit less than 512Kb, while still providing other tools you will need like awk, grep, sed.

Bash and Busybox shell are similar enough for most uses. If your script is using POSIX features of Bash shell it will work in Ash shell too.

The shebang

Scripts in OpenWrt should have #!/bin/sh at the first line, #!/bin/bash will not work.

Automated shell script checking

Write your bash scripts with #!/bin/sh first line in and it will check for features you cannot use in OpenWrt shell. see the

Check if a tool is available

You may need to install additional command line tools in OpenWrt, as the default installation is very minimal. A Desktop PC Linux like Ubuntu has much more command line tools in default install.

Check if a tool is available by writing type tool-name and it will answer you where this tool is, or an error if there is no such tool installed. Use the package table or index (Packages link in the sidebar to the left of this article) to find the package with the tool you need.

# type time
time is /usr/bin/time

See also: Configuration in scripts

docs/guide-developer/write-shell-script.txt · Last modified: 2019/05/09 17:48 by vgaetera