Hello, World! Your first Shell program - AkuCode
Shell Script or also commonly known as Bash is a file that contains one
or more commands that you will type on the command line (Command Line). This
first article will explain how to create a file like that and make it
executable. And it also includes a few other issues around Bash, including what
name should be given for the file, where we saved it, and how to run it.
We will start with the first program that is shown
simply in each language of the computer: The program prints "Hello,
World!" in your terminal. It's very simple programming, but it's enough
to show an important concept on a bash scavamping. The code itself is the
simplest part of this first discussion. Naming the file and deciding where to
put it is not complicated, but it's very important to know.
For the most part in this learning, you can also run
it in the terminal. At this time I'm using Windows 10 so I will use Ubuntu
virtual Terminal from windows subsystem
Linux. The command Program you type will be executed
immediately after you press ENTER.
First, open your Ubuntu virtual terminal and make sure it is in its default directory or home directory, by "echo $HOME" and press ENTER:
After that, the code is no more than: "echo
Hello, World!", and the result is like this;
There are three words on the command line: The command
itself and the two arguments. The "echo" command to print the
argument is separated by a single space and ends with a new line.
File, before you convert the code to a script, you
have to make two decisions: What name will be used to call the file and be the
name of the file, then where you will center. The name must be unique (that is,
it should not contradict other commands), and you should put it in place of
bash can find it.
Naming scripts, on beginners, usually often occur when
experiments call scripts. To see why it's bad, enter the following command in
Terminal: "Type Test"
The "type" command tells you what is going to be executed by the shell (and where it can be found if it is an external file) for each given command. In bash, type "-a test" will display all the commands that match the name ' test ':
As you'll see the command named ' Test ' already exists; This is used to test the file type and to compare the values, if you call the experiment script, it will not execute when you write ' test ' in command-line bash; The first commandment identified by type will be executed in its stead.
Typically, the UNIX command name or bash Shell is very short as possible. They are the first two consonants of the descriptive word (e.g. MV for Move or LS to display List) or the first letter of the descriptive phrase (e.g., PS to Process Status or sed for Stream Editor)
To practice this time call the script HW. Many bash programmers add the suffix, like (. sh) to indicate that the program is a bash script. The script does not need it, and I only use it for the program being worked on. I added (. sh), and when the program finishes I'll delete it. Shell scripts become other commands and do not need to be distinguished from other types.
To practice this time call the script HW. Many bash programmers add the suffix, like (. sh) to indicate that the program is a bash script. The script does not need it, and I only use it for the program being worked on. I added (. sh), and when the program finishes I'll delete it. Shell scripts become other commands and do not need to be distinguished from other types.
Comments