IntelliJ IDEA 2021.1 Help

Shell scripts

IntelliJ IDEA provides coding assistance for shell script files: completion (including local paths), highlighting, quick documentation, textual rename refactoring, and more.

Coding assistance for shell scripts

It also includes a special type of run/debug configurations for shell scripts.

IntelliJ IDEA integrates with several external tools to enhance shell script support:

  • ShellCheck is a shell script static analysis tool that can detect syntax errors, semantic problems, corner cases, and typical pitfalls. IntelliJ IDEA will prompt you to install it if it is not available.

  • Shfmt is an external formatter engine for shell scripts. IntelliJ IDEA will suggest installing it when you reformat the code Ctrl+Alt+L of the shell script for the first time.

  • Explainshell is a website that can parse any shell command and provide help text for each argument. Access to it is available via an intention action: press Alt+Enter and select Explain shell.

Configure files recognized as shell scripts

By default, IntelliJ IDEA recognizes files with the following extensions as shell scripts: .sh, .bash, .zsh. However, you can configure IntelliJ IDEA to recognize any file types as shell script files (for example, if you want to edit .csh files).

  1. In the Settings/Preferences dialog Ctrl+Alt+S, select Editor | File Types.

  2. In the Recognized File Types list, select Shell Script and add the necessary patterns in the File Name Patterns list below.

  3. Click OK to apply changes.

Run shell script files

When working on a shell script file, you can click The Run icon in the gutter to run it in the built-in Terminal. This creates the Shell Script run configuration (if it doesn't already exist for this file) and launches it. To create the Shell Script run configuration manually for any arbitrary file, do the following:

  1. From the main menu, select Run | Edit Configurations.

  2. Click The Add button and select Shell Script.

  3. Specify the path to the script file and options that you want to pass to the script when it is launched. You can also change the interpreter for running the script and additional options for the interpreter. If necessary, add tasks that you want to automatically launch before running this script file.

  4. Click OK to save the run/debug configuration.

To run the configuration, press Alt+Shift+F10 and select the created shell script configuration.

You can also run the shell script from the context menu: right-click the file in the Project tool window or anywhere in the editor tab of the shell script file.

Last modified: 08 March 2021