4 | user input(read command)

Shell Scripting Tutorial


Hello Programmers, I’m Yash. Sole programmer at planetvearcity – a place where programmers come to learn, build, and grow.

Welcome to the tutorial series on shell scripting. In this video, we will cover the read command. To get input from the keyboard, we the read command. The read command takes input from the keyboard and assigns it to a variable.



3 | variables

Shell Scripting Tutorial


Hello Programmers, I’m Yash. Sole programmer at planetvearcity – a place where programmers come to learn, build, and grow.

Welcome to the tutorial series on shell scripting. In this video, we will cover variables.

The definition of a variables-a chunk of memory to which we can allocate values, interpret and manipulate its contents. Every programming language in existence has the concept of variables. There is no exception to the Bourne shell.

One thing to note is that when we declare variables along the way there should be no space around = sign. So let us get started.

The shell does not care about types of variables; they may store strings, integers, real numbers. Actually, these are all stored as strings.



2 | comments

Shell Scripting Tutorial


Hello Programmers, I’m Yash. Sole programmer at planetvearcity – a place where programmers come to learn, build, and grow.

Welcome to the tutorial series on shell scripting. In this video, we will cover comments and variables.

When writing Shell scripts, it is always a good practice to make your code clean and easily understandable. One of the ways to improve the readability of your code is by using comments. Adding comments to your scripts will make it easy for you to understand your code in the future. Let us go ahead and try using comments.

Comments are also useful when testing a script. Instead of deleting some lines, you can comment them out. If you are using a code editor like me then there is a shortcut to comment a given line or selected portion. In vs code its command plus forward slash.



1 | introduction

Shell Scripting Tutorial


Hello, I’m Yash. Sole programmer at planetvearcity – a place where programmers come to learn, build, and grow.

Welcome to the new tutorial series on shell scripting. In this video, we will be covering the introduction of shell scripting and write a hello world script.

Before we begin. I recommend you guys to watch my Linux command line tutorial. I have posted the link in the description. That tutorial is a prerequisite to this tutorial series. Moving along I will assume you understand basic Linux commands.

The shell script is a computer program designed to be run by the Unix/Linux.

There many different types of the shell such as:

  1. The Bourne Shell
  2. The C shell
  3. The Korne Shell
  4. The Bourne-Again shell


19 | sudo command

Linux Command Line Tutorial


  1. In this tutorial, we will learn how to use sudo command.
  2. The sudo command allows you to run programs as another user, by default the root user.
  3. Sudo is one of the commands you use very often if you spend a lot of time on the command line.
  4. Using sudo as root instead of login is better since you can give individual users restricted administrative rights without knowing the root password.


18 | octal(777) chmod

Linux Command Line Tutorial


Everything is similar to the previous two videos in the series. The only difference is in this video we will learn how to use chmod with octal numbers.

In Octal

  • r = 4
  • w = 2
  • e = 1

This tutorial covers how to use the chmod command to change the access permission of files and directories.

In Linux, the file is associated with an owner and a group and assigned with permission access rights for three different classes of users:

  • The file owner
  • The group members
  • Others(everybody else)

File permissions can be changed. In order to do that we make use of chmod command.

There are three file permissions that apply to each class:

  • The read permission
  • The write permission
  • The execute permission
-rw-r--r-- 12 yash staff 128 Oct 2 12:31 myfile.txt
|[-][-][-]- [------] [---]
| | | | | | |
| | | | | | +-----------> 7. Group
| | | | | +-------------------> 6. Owner
| | | | +--------------------------> 5. Alternate Access Method
| | | +----------------------------> 4. Others Permissions
| | +-------------------------------> 3. Group Permissions
| +----------------------------------> 2. Owner Permissions
+------------------------------------> 1. File Type


17 | directory and chmod

Linux Command Line Tutorial



Everything is similar to the previous video the only difference is we will see the behavior of directories and its contents when changing their permissions.

This tutorial covers how to use the chmod command to change the access permission of files and directories.

In Linux, the file is associated with an owner and a group and assigned with permission access rights for three different classes of users:

  • The file owner
  • The group members
  • Others(everybody else)

File permissions can be changed. In order to do that we make use of chmod command.

There are three file permissions that apply to each class:

  • The read permission
  • The write permission
  • The execute permission
-rw-r--r-- 12 yash staff 128 Oct 2 12:31 myfile.txt
|[-][-][-]- [------] [---]
| | | | | | |
| | | | | | +-----------> 7. Group
| | | | | +-------------------> 6. Owner
| | | | +--------------------------> 5. Alternate Access Method
| | | +----------------------------> 4. Others Permissions
| | +-------------------------------> 3. Group Permissions
| +----------------------------------> 2. Owner Permissions
+------------------------------------> 1. File Type


16 | file and chmod

Linux Command Line Tutorial



This tutorial covers how to use the chmod command to change the access permission of files and directories.

In Linux, the file is associated with an owner and a group and assigned with permission access rights for three different classes of users:

  • The file owner
  • The group members
  • Others(everybody else)

File permissions can be changed. In order to do that we make use of chmod command.

There are three file permissions that apply to each class:

  • The read permission
  • The write permission
  • The execute permission
-rw-r--r-- 12 yash staff 128 Oct 2 12:31 myfile.txt
|[-][-][-]- [------] [---]
| | | | | | |
| | | | | | +-----------> 7. Group
| | | | | +-------------------> 6. Owner
| | | | +--------------------------> 5. Alternate Access Method
| | | +----------------------------> 4. Others Permissions
| | +-------------------------------> 3. Group Permissions
| +----------------------------------> 2. Owner Permissions
+------------------------------------> 1. File Type


15 | echo command

Linux Command Line Tutorial


ANSI Escape Code
https://en.wikipedia.org/wiki/ANSI_escape_code#Colors

In this video, we will learn how to use the echo command. The arguments passed to echo are printed to the standard output.

Echo is commonly used in shell scripts to display a message or output the results of other commands.

Although it is not necessary to enclose arguments in double-quotes it is good practice to do so.

If using ” each character enclosed within is preserved. Variable and commands will not be expanded.

Echo can be used with pattern matching characters, such as the wildcard characters.

echo "My txt files are: *txt"

Creating a variable in the shell for the current session. Don’t leave any space between equal sign.

myString="Hello World"
x=10

Display variable:

echo $myString
echo "x"

Echo can redirect commands output.

echo "Directory contents: $(ls -l)"


Options

CommandEffect
^OSave changes
^XExit nano
Save and Exit commands