• /bin/bash Bash Scripting 83
  • Your First Script: “Hello, Hackers-Arise!”




    Download 7,3 Mb.
    Pdf ko'rish
    bet86/115
    Sana27.11.2023
    Hajmi7,3 Mb.
    #106243
    1   ...   82   83   84   85   86   87   88   89   ...   115
    Bog'liq
    linuxbasicsforhackers

    Your First Script: “Hello, Hackers-Arise!”
    For your first script, we will start with a simple program that returns a 
    message to the screen that says 
    "Hello, Hackers-Arise!"
    Open your text 
    editor, and let’s go.
    To start, you need to tell your operating system which interpreter you 
    want to use for the script. To do this, enter a shebang, which is a combina-
    tion of a hash mark and an exclamation mark, like so:
    #!
    You then follow the shebang (
    #!
    ) with 
    /bin/bash
    to indicate that you want 
    the operating system to use the bash shell interpreter. As you’ll see in later 
    chapters, you could also use the shebang to use other interpreters, such 
    as Perl or Python. Here, you want to use the bash interpreter, so enter the 
    following:
    #! /bin/bash


    Bash Scripting
    83
    Next, enter the 
    echo
    command, which tells the system to simply repeat 
    (or echo) back to your monitor whatever follows the command.
    In this case, we want the system to echo back to us 
    "Hello, Hackers-Arise!"

    as done in Listing 8-1. Note that the text or message we want to echo back 
    must be in double quotation marks.
    #! /bin/bash
    # This is my first bash script. Wish me luck.
    echo "Hello, Hackers-Arise!"
    Listing 8-1: Your “Hello, Hackers-Arise!” script
    Here, you also see a line that’s preceded by a hash mark (
    #
    ). This is a 
    comment, which is a note you leave to yourself or anyone else reading the 
    code to explain what you’re doing in the script. Programmers use com-
    ments in every coding language. These comments are not read or executed 
    by the interpreter, so you don’t need to worry about messing up your code. 
    They are visible only to humans. The bash shell knows a line is a comment 
    if it starts with the 
    #
    character.
    Now, save this file as HelloHackersArise with no extension and exit your 
    text editor.

    Download 7,3 Mb.
    1   ...   82   83   84   85   86   87   88   89   ...   115




    Download 7,3 Mb.
    Pdf ko'rish

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    Your First Script: “Hello, Hackers-Arise!”

    Download 7,3 Mb.
    Pdf ko'rish