We need to use a text editor; of course, you can use your favorite one. Linux Mint offers us several text editors such as Vim, Emacs, and Pluma. The latter has a graphical user interface and is installed by default, so we'll use it for our work. Here's how to get started:
Click on the Menu button, and then click on the Text Editor menu option, as shown in the following screenshot:
A new window will be displayed, and you'll be ready to use Pluma. Enter the following lines, and save the file as
myscript.sh
when you're ready:#!/bin/bash if [ -f "myfile.txt" ] then echo "Sorry, file already exists." else echo "Content for file" > myfile.txt fi ls -l myfile.txt
Give execution permissions to your new shell script:
$ chmod +x myscript.txt
Launch your script:
$ ./myscript.sh
The output of the last command should be something like the following:
-rw-rw-r--. 1 arturo arturo 17 Oct 20 11:12 myfile.txt
Also, you can check the content...