Results 1 to 5 of 5

Thread: .sh file help

  1. #1
    Join Date
    Feb 2020
    Beans
    1

    .sh file help

    How do you run commands from a .sh file. I've been looking on for how to make on but the only one i found was how to print text on the screen.

  2. #2
    Join Date
    Jun 2014
    Beans
    7,383

    Re: .sh file help


  3. #3
    Join Date
    Mar 2007
    Location
    Promiseland
    Beans
    1,549
    Distro
    Xubuntu 22.04 Jammy Jellyfish

    Re: .sh file help

    If you interested in more, check out this....
    https://linuxconfig.org/bash-scripti...-for-beginners
    Cheers,


    The Linux Command Line at http://linuxcommand.org/

  4. #4
    Join Date
    Mar 2007
    Location
    Denver, CO
    Beans
    7,958
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: .sh file help

    When you say run commands from your shell script -- do you mean it's calling another shell script? Can you give an example? I'm thinking of a term call command substitution $( ) which some people used to do with `......`

  5. #5
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: .sh file help

    Quote Originally Posted by dagamegamer View Post
    How do you run commands from a .sh file. I've been looking on for how to make on but the only one i found was how to print text on the screen.
    TLDP is full of useful guides.
    The
    Linux
    Documentation
    Project

    https://tldp.org/

    https://www.tldp.org/LDP/Bash-Beginn...ers-Guide.html

    BTW, Unix systems don't care about file extensions. .sh doesn't mean anything special to the system. It is slightly handy for humans, but humans lie. I've created a few .sh files, but they quickly outgrew the complexity I was willing to implement using Bourne Shell (that where "sh" originated), so I re-implemented them in a much more powerful scripting language, perl5. I could have changed the name to .pl, but I'm lazy and left it as .sh. No matter, it works just fine provided 3 things are true.
    1. File is readable by the userid trying to run the script
    2. File has eXecute permissions for the user running the script
    3. the 1st line correctly says, in the correct way, which interpreter to be used by the script

    chmod +r path-to-file
    chmod +x path-to-file
    1st line has interpreter, specified, for example:
    Code:
    #!/bin/bash
    The #! is critical - # is a comment. #! says, use this interpreter. It must be on the 1st line, not the 2nd, 5th, 900th line, the 1st line of the script. Every line after that must be compatible with whatever interpreter is specified.
    More interpreter examples:
    Code:
    #!/bin/sh
    Code:
    #!/bin/ksh
    Code:
    #!/usr/bin/perl
    Code:
    #!/usr/bin/python
    Code:
    #!/usr/bin/python3
    Code:
    /home/tf/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
    There are many more perfectly acceptable scripting languages. Use whatever you like.

    If you want examples of full programs in 500+ languages, check out http://rosettacode.org/wiki/Main_Page . Both scripted and compiled language examples are there. Some of the script examples are missing that 1st line, but that's it. They are full implementations.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •