shfmt command not found

In this troubleshooting guide we learn how to fix shfmt command not found error message

Introduction

When you run more command in linux terminal / console, you get the following error message

shfmt: command not found

or when using sudo you get the following error message

sudo: shfmt: command not found

Solutions to shfmt: command not found

How To Fix shfmt: command not found in Ubuntu / Debian / Kali Linux / Raspbian

In Ubuntu shfmt is provided by shfmt package.

shfmt is:

shfmt is a shell formatter, parser, and interpreter. It supports POSIX Shell, Bash, and mksh.

shfmt’s default shell formatting was chosen to be consistent, common, and predictable. Some aspects of the format can be configured.

shfmt can also replace bash -n to check shell scripts for syntax errors and bashisms. It is more sophisticated and the output is friendly.

For Continuous Integration (CI) tests, one can use a variant where formatting changes are just shown as diffs.

Main features:

  • List files whose formatting differs from shfmt’s.
  • Print syntax tree to stdout as a typed JSON. This can be useful to analyze shell scripts.
  • Minify the code to reduce its size.
  • Error with a diff when the formatting differs.
  • Recursively find all shell files and print the paths.

To fix this problem, we can install more using the command below.

sudo apt-get -y install shfmt

This command might take some time to finish depending on your machine internet connection.

You can also use apt command to install shfmt.

sudo apt -y install shfmt

Or if you have aptitude installed you can use the following command.

sudo aptitude install shfmt

Summary

In this tutorial we learn how to fix shfmt command not found error in Ubuntu / Debian / Kali Linux or Raspbian distribution.