Visual Studio Code – Linux

Step 5: Install extensions on the remote host.

Having established a successful connection to the remote host through VS Code, we can now move forward by installing the necessary extensions to facilitate the execution of a bash script within VS Code. To install these extensions on the remote host, it is essential to confirm that the host has external internet access, either directly or via a proxy (utilizing the http_proxy and https_proxy environment variables).

Access the EXTENSIONS search by pressing CTRL+Shift+X. Search and install the below extensions:

  • Bash IDE, the bash language server
  • ShellCheck, optional shell script linter
  • shell-format, optional script formatter

Step 6: Create a workspace for your files.

To commence your coding journey, the first step is to create a workspace; a dedicated folder where you organize and store all your files. VS Code has no command for creating a workspace. Instead, the process involves creating a folder from the Linux terminal and then adding that folder to a workspace from VS Code.

  • From the remote Linux host run, mkdir to create a folder
  • VS Code UI → File → Add Folder to Workspace . Select the folder to add
  • VS Code UI → File → Save Workspace As..” to save the workspace. This action will also generate a JSON config file within the folder. The JSON config file contains paths to the folders that constitute your workspace.

Upon reconnecting to the remote host later, navigate to ‘File → Open Workspace from File…’ in VS Code. Specify the location of the JSON configuration file to seamlessly resume working on your project.

Step 7: Add  a file to your Workspace

Now that everything is configured, you’re all set to begin. Start by adding a file and commence writing your code. Press CTRL + SHIFT + E to go the EXPLORER and then add files and folders.

I added a file named “jtest.sh” with a simple bash script as shown below. I also intentionally introduced a syntax error to observe the linting action of the ShellCheck extension. The error will be highlighted under the Problems tab. After correcting the error, you can simply right-click on the editing area and choose “Format Document” to format the document by the Shell-format extension.

Step 8: Running your Script

Execute your script directly from the Terminal session on the Linux host. Pressing CTRL + ` to toggle the visibility of the terminal. Alternatively, you can run it from the VS Code UI by navigating to Terminal → Run Active File.

Running with debugging in VS Code is also an option, but it requires the installation of a debugger such as “Bash Debug”.