The two commands you have just learned,
echo
and
read
, are straightforward. But as scripts become longer and more complex, the meaning of commands is sometimes difficult to determine. This is especially true when:
- You wrote the shell script months (or years) ago and cannot recall exactly how you did things
- Someone else wrote a shell script and you need to update it or use it as the basis for another project
- You want to improve the appearance of the shell script to make it easier to follow what’s going on in it
You can use sed command to comment lines between two line numbers. Example:
sed -i '10,30 s/^/#&/' mycode.sh
Above code will comment the code between line 10&30.
The next lesson describes how to set a shell script file’s permissions to allow it to be executed.