How to on basic bash shell scripting?



  • Here are some basics on bash shell scripting (shell programming)

    Create a script using an editor like nano or vi in your home directory

    Note: Nano is more beginner friendly, best to use nano editor if you are new to unix/linux editors.

    $ vi myscript
    

    Add these two lines to the top of the file and save the file

    tropicalfruit=pineapple
    echo My fruit is $tropicalfruit
    

    Change the permission on the file so it has execute permissions

    $ chmod 754 myscript 
    $ ls -l
    total 4
    -rwxr-xr-- 1 trainer trainer 56 Jan 17 07:00 myscript
    

    Run the script, the dot, slash mean run from current directory

    $ ./myscript 
    My fruit is pineapple
    

    That's it you've written your first script, what goes into the script the real power, the logic, programming.


Log in to reply
 

© Lightnetics 2024