Simple Linux Script

a minute read

Linux_logo_errorbits.com

First Linux Script

In this first script I will show you all the details and preparations that you will need to do prior creating an running your first Linux script. I will use VIM text editor (see the tutorial in the link), but you can use any editor that you might like.

Go to the folder in which you want to create the file for the script and type:

vim test.sh

The editor will create a new file called test.sh (if the file already exist, it will be opened for editing), then input the following commands in the file:

#!/bin/sh
echo “This is my first Linux script”
echo “I will learn more advanced Linux scripts…”
echo “… but a little bit later”

Save your script and exit editor.

Make sure that your file is allowed to run by running chmod command (see the permissions tutorials: File permissions in Linux and Permissions in Linux: Octal/Absolute mode):

chmod +x test.sh

Run the script file with:

./test.sh

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

Related Posts:

To execute a shell script on Linux, you need to follow these steps:Open a terminal: Launch the terminal application on your Linux system. You can usually find it in the applications menu or by using the keyboard shortcut Ctrl+Alt+T. Navigate to the script'...
To create a link to a script on Linux, you can use the ln command.The general syntax for creating a link is: ln -s <source_file> <destination_link> Here, <source_file> represents the path to the script you want to link, and <destination_li...
In Bash scripting, command-line arguments allow you to provide input and parameters to a script during execution. Here's an overview of how to handle command-line arguments in a Bash script:To access the command-line arguments, you can refer to them using ...
To write a basic Bash script, follow these steps:Open a text editor and create a new file with a .sh extension (e.g., script.sh).Start the script with a shebang, which tells the system to interpret the commands using Bash. Use "#!/bin/bash" at the begi...
To run a bash script during a Docker run, you can follow these steps:Start by creating a Dockerfile. This file will define the build process for your Docker image. You can use a text editor to create this file. In the Dockerfile, specify the base image you wan...
To redirect the output of a bash script to another file, you can use the ">" symbol followed by the filename. Here's how to do it:Open the terminal and navigate to the directory where your bash script is located. Use the following syntax to redi...