Topic 10

Date: 3/22/2017
Linux shell scripting tutorial
Linux System Administration

Shell scripting exercises

  • Create a new directory bash_scripts where you will run the shell scripting exercises.
    mkdir  bash_scripts
    cd bash_scripts

    Note, it is recommended to create a new script file for every exercise; make them executable; give them names with extension .sh -- it is just a convention rather than a must. The first line of a bash script starts with
    All non-executable comments in a script are prepended with #
    # For example, we list all the files in the current directory
    ls -la
    ls -l /etc  # Comment. Here, we list files in /etc directory 

  • Script is like a calculator:
    echo "I will work out X*Y"
    echo "Enter X"
    read X
    echo "Enter Y"
    read Y
    echo "X*Y = $X*$Y = $[X*Y]"
    Make the script executable and run
    chmod 755

    References: for details, consult Bash Guide for Beginners

  • Take me to the Course Website