linuxubuntushdaemons

How can I create .sh extension file in Linux Ubuntu?


I'm trying to write a script to run one of my .jar files as daemons, but I am not understanding how to create a .sh extension file in Ubuntu. I have already used vi to create a file with the code that I want, but I cannot figure out how to define the file to specifically be a .sh file. For example, I want to convert my file "foo" or "foo.txt" into "foo.sh".

Is there a simple command I am not seeing that can convert files to a .sh extension or is it a more complicated process?


Solution

  • Use this as a template:

    #!/bin/bash
    
    # content of your script
    

    The first line is called a shebang and tells the OS what program that should be used executing the content of the file, in this case, bash.

    To make the file executable:

    chmod 755 foo.sh
    

    To execute your script do:

    ./foo.sh