[For black screen phobia] I want to know about Linux and shells, so I illustrated it loosely.

Introduction

This is the file I want to create this time.

200216_01.png

It's just a ** batch ** that sends JSON to the app server when executed **.

Use the curl command! However, I was the first to create a batch (→ shell file), let alone the curl command, so I studied the touch part of the shell and Linux commands.

I've been touching HTML, CSS, and Java for a while, so I'm a super beginner with Linux commands! I was surprised at how different it was, so I will summarize it as a memorandum.

Since I innocently -rm -r the log directory, I'm not good at black screens to death, but I don't feel like I was able to reconcile a little after making a batch, so my parents were killed by the black screen. I hope it helps the understanding of everyone who has been burned.

In this article, I will briefly explain the following contents for human beings who do not know the kernel or shell.

--Linux kernel --Shell --Shell script --Batch and shell

Before learning the shell: What is the kernel and shell?

A shell is ** software that interfaces with the Linux kernel **.

… Linux kernel?

==========

→ Read A if you think "Linux kernel? It is the core part of Linux OS that manages hardware such as CPU and process management such as command execution?"

→ If you think "Linux kernel? What's that?", Read B.

==========

A: I know about the Linux kernel! Those who say that will not have time to read 3000 characters in the future, so please go back to the browser or write information on delicious ramen shops in the rice field!

B: Let's read this article and study together! !! !! !!

==========

Again, the Linux kernel is the core of the Linux OS, which manages hardware such as the CPU and processes such as command execution. (I think that OSs other than Linux also have kernels and shells, but this time I read Linux OS book, so I will talk on the assumption of Linux ... !)

200216_02.png

The Linux kernel cannot be operated by direct command input. The shell exists as a user interface for executing commands and specifying input / output destinations.

For example, when you open the macOS terminal (black screen), the following words are displayed by default.

Last login: Sun Feb 16 15:49:26 on hogehoge
hoge@localhost ~ % 

This is the prompt that the shell is displaying. Software called shell is waiting for command input. (The above used macOS Catalina. The default shell is zsh. The prompt display is ~ $ for bash, and the part of the user name and host name differs depending on the terminal)

What is a shell script?

You can use the "black screen" of a macOS terminal or a free terminal emulator (Tera Term, etc.) to give instructions to the shell directly from the command line (** interactive operation **, interactive operation).

On the other hand, as with many programming languages, you can also write shell commands in a file in advance and start it by reading the file. The file prepared in this way is called a shell script.

As illustrated in the figure above, the shell has various types such as sh, bash, csh, dash, zsh [https://ja.wikipedia.org/wiki/Unix%E3%82%B7%E3%] There are 82% A7% E3% 83% AB #% E5% 88% 86% E9% A1% 9E).

In "New Linux Textbook", sh or bash is mainly used as a shell script at present, but bash is recommended for the following reasons. That is.

--The implementation of sh is slightly different for each Linux distribution [^ 1]. --Since sh has been around for a long time, there are few essential functions for writing shell scripts. --Even the addition of 1 requires the use of the external command expr

Also, the curl command I want to use this time seems to be you need to insert the eval command if it is sh. It's frustrating, so I think bash is better if you want to get started easily!

[^ 1]: It's a Linux package, which I won't explain in detail here. In addition to the Linux kernel, commands and applications that can be used from the beginning are included, and each is slightly different. Even if you buy the same manga, the postcards, stickers, figures, etc. that come with the benefits will differ slightly depending on the store you purchased. The specific names you often hear are Ubuntu, CentOS, etc.

Batch and shell

I'm completely saying shell shell, "By the way, why don't you say that you made a" batch "at the beginning? Where did the batch go? Is the batch and shell the same? " Tsukkomi came in from someone in my heart.

By the way, I was asked to make a "batch" myself, but I actually made a shell (a shell script using bash), so what? have become.

From what we've seen so far, "shell" has the following meanings.

  1. Interface software that wraps the kernel
  2. Abbreviation for shell script (general term for sh, bash, zsh, etc.)
  3. One of the shell types, "sh" (It's called Bourne Shell in short)

200217_01.png

Similarly, "batch" has many meanings.

1. Batch processing

To execute one stream of programs (jobs) sequentially on a computer. A computer term that indicates performing predetermined processes at once. Opposite words are interactive / interactive or real-time processing. Batch processing-Wikipedia

Whereas the act of "typing a command directly into the shell from the" black screen "" that came out earlier was ** interactive operation **, ** batch processing ** is to perform predetermined processing at once. Point to. In other words, starting a shell script under predetermined conditions and performing processing is also "batch processing".

200217_02.png

(The figure is just an image. Normally, I don't think I'll make a job with different extensions ...)

2. Batch file

A text file that describes the command sequence that you want to execute at the command prompt (shell) on MS-DOS, OS / 2, and Windows. [Batch file-Wikipedia](https://ja.wikipedia.org/wiki/%E3%83%90%E3%83%83%E3%83%81%E3%83%95%E3%82%A1% E3% 82% A4% E3% 83% AB)

This is functionally similar to a shell script. Although it is a companion as a scripting language, it is a batch file ≠ shell script file. As an example, let's compare in a very simple Hello World.

Hello World in batch file
@echo off
echo Hello World
pause > nul
Hello World in shell script (bash)
#!/bin/bash
echo "Hello World"
exit 0

There are some similar commands, such as the echo command, but you can see that they are basically different languages. I also ls at the command prompt and become a key, often.

The super-easy way to tell is that the extension is different.

--Batch file: .bat --Shell script file: .sh

Right? Isn't it easy? (Please don't ask me in more detail, I will cry)

in conclusion

o (・ \ _ ・ = ・ _ ・) o <Are ~? Where is the curl command?

Actually, after this, explain Frequently used Linux commands, explain the curl command, explain some options, and actually make it. I wanted to introduce the place I was addicted to ...

The number of characters has already increased so far, so this time I will stop here!

Even with this, I wrote UNIX and Distribution quite a bit, so I'm interested. Some people try to jump to the link!

Thank you for reading.

Recommended Posts

[For black screen phobia] I want to know about Linux and shells, so I illustrated it loosely.
I want to know how LINUX works!
I studied about Linux, so I summarized it.
[Qualification] I passed LinuC Level 1, so I will write about how to study and how it was.
I want to know the features of Python and pip
I want to know the legend of the IT technology world
[Linux] I want to know the date when the user logged in
I want to create a pipfile and reflect it in docker
(Beginner) I don't understand SSH and Linux command ssh-keygen, so I summarized it.
I want to know more about individual developers. YouDev has been released.
I want to use Linux on mac
Join Azure Using Go ~ For those who want to start and know Azure with Go ~
I want to write an element to a file with numpy and check it.
I want to convert horizontal text to vertical text and post it on Twitter etc.
Docker x visualization didn't work and I was addicted to it, so I summarized it!
I set up TensowFlow and was addicted to it, so make a note