Enrollments Open for Certification Course on Artificial Intelligence and Deep Learning by IIT Roorkee

  Apply Now

Linux Basics

57 / 85

Writing first shell script

A shell script is a file containing a list of commands. Let's create a simple command that prints two words:

  1. Open a text editor to create a file myfirstscript.sh:

    nano myfirstscript.sh
  2. Write the following into the editor:

    echo "hello $name world"

    Note: In Unix, the extension doesn't dictate the program to be used while executing a script. It is the first line of the script that would dictate which program to use. In the example above, the program is /bin/bash which is a Unix shell.

  3. Press Ctrl+X to save and then Y

  4. It will ask for a filename, check if its myfirstscript.sh. If not enter the same filename.
  5. Hit Enter key to exit

  6. Now, by default, it would not have executable permission. You can make it executable like this:

    chmod +x myfirstscript.sh
  7. To run the script, use:


No hints are availble for this assesment

Answer is not availble for this assesment

Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...