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

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
docs/guide-developer/write-shell-script.txt · Last modified: 2019/09/08 11:47 by tmomas