How do I create a batch file and run it? [duplicate]

To create one use the .sh extension but it doesn't really matter but it helps future users to quickly determine which file type it is. The bat name is mostly used on Windows but in Linux file name extensions do not really matter. Meaning I can call my file say run.de and it would still run in bash file but I believe it's a good practice to name them with the .sh file extension.

For the editor, part uses any that is best for you between nano vim gedit emacs, but I believe gedit would be nice to start with.

How to:

using gedit text editor:

  1. Create the file:

    gedit runme.sh
    
  2. Add code into file:

    #!/bin/bash 
    
    
    echo "Hello World!"
    
  3. Make file executable:

    chmod +x runme.sh
    
  4. Run the file from terminal:

    ./runme.sh
    

In linux they are bash scripts. You can use most any editor and you can call it what you wish, Linux does not use extensions such as .sh or .bat or .exe to .doc to identify files, it uses magic.

Probably gedit for a graphical editor and nano from the command line.

Avoid word processors such as libre office as they add headers you don't want.

http://www.linfo.org/magic_number.html

To write a bash script , start the file with a "SheBang" or #!/bin/bash

#!/bin/bash

# comments start with a '#"

command 1
command 2

Tons of tutorials on the web - https://linuxconfig.org/bash-scripting-tutorial