# Shell Principles

## *เชลล์ (Shell)*

shell เป็นตัวกลางในการรับคำสั่ง (Command Line) จากผู้ใช้แล้วจะทำการแปลชุดคำสั่ง (Command Line Interpreter - CLI) ที่ผู้ใช้ป้อนเข้ามา โดยขบวนการภายในตัว shell จะซ่อนรายละเอียดอันซับซ้อนของระบบปฏิบัติการเอาไว้ โดยที่ผู้ใช้จะไม่รู้ว่าหลังจากที่ป้อนคำสั่งไปแล้วภายในจะต้องมีขบวนการเช่นไรบ้าง ตัวอย่างเช่น ถ้าผู้ใช้ต้องการทราบหน่วยความจำที่เหลือหรือพื้นที่ของฮาร์ดดิสก์ที่เหลืออยู่ ผู้ใช้เพียงพิมพ์คำสั่ง free/df ตัว shell ก็จะทำหน้าเชื่อมต่อและเข้าไปจัดการในหน่วยความจำหรือฮาร์ดดิสก์ให้ตรวจสอบตัวเองว่าขณะนี้มีการใช้งานเก็บข้อมูลไปเท่าไหร่แล้วและเหลือพื้นที่ให้ใช้งานได้อีกเท่าไหร่ ซึ่งขบวนการดังที่ได้กล่าวข้างต้นเป็นการติดต่อสื่อสารในระดับล่างที่เรียกว่าระดับเคอร์เนล ซึ่งถือได้ว่าเป็นแกนกลางสำคัญในการควบคุมการทำงานระบบทั้งหมดภายในเครื่องคอมพิวเตอร์ โดยจะกล่าวถึงรายละเอียดของเคอร์เนลในบทถัดๆไป &#x20;

นอกจากนั้น shell ยังสามารถรองรับการเขียนชุดคำสั่งมากกว่าหนึ่งคำสั่งพร้อมกัน และสามารถรับชุดคำสั่งล่วงหน้าให้ทำงานตามเงื่อนไขต่างๆที่ได้กำหนดไว้ในลักษณะสคริปท์ (Script) ที่ถูกเก็บลงในไฟล์ได้ ทำให้เพิ่มความสะดวกและมีประสิทธิภาพในการใช้งานระบบปฏิบัติการลีนุกซ์ โดยเฉพาะผู้ใช้ที่มีทักษะอยู่ระดับหนึ่งในการเขียนสคริปท์หรือที่เรียกกันว่าเชลล์สคริปท์ (Shell script) นั้น และนอกจากนั้นลูกเล่นความสามารถจะมากน้อยเพียงใดก็ยังขึ้นอยู่กับยี่ห้อหรือรุ่นโปรแกรม shell นั้นด้วย ในปัจจุบัน shell ที่มีอิทธิพลและเป็นที่นิยมมากที่สุดตัวหนึ่งคือ [Bourne shell](http://en.wikipedia.org/wiki/Bourne_shell) (ปัจจุบันกลายเป็น Bourne Again shell) และ [C shell](http://en.wikipedia.org/wiki/C_shell)&#x20;

<figure><img src="/files/CqUjqRTZQJ72TpYqJQAq" alt=""><figcaption><p><em>ขบวนการทำงานของ Shell</em> </p></figcaption></figure>

## ปฏิบัติ

Link: [Command line interface](https://www.tutorialspoint.com/linux_terminal_online.php)

## BDH Shell for PSOC™ 6S2

BDH Shell is developed and customized based on NT-Shell (Natural Tiny Shell) is a C library for embedded systems. It provides [VT100 compatible](https://en.wikipedia.org/wiki/VT100#/media/File:DEC_VT100_terminal.jpg) terminal control feature and needs only serial read/write functions for the porting.

<figure><img src="/files/fnsOqOsIIKCDSUljRQgd" alt=""><figcaption><p>NT Shell Architecture</p></figcaption></figure>

### Features

* Compatible with VT100
* Really simple.
  * The API has only three functions.
  * It consists of only three small modules.
* Highly portable.
  * Compatible with C89.
  * No dependencies. (even libc!)
  * No dynamic memory allocation. (no need a operating system!)
* Small code foot print.
  * ROM: 10KB
  * RAM: 1KB

### Edit Controls

<table><thead><tr><th width="237">Shortcut</th><th>คำอธิบาย</th></tr></thead><tbody><tr><td>Ctrl + A or Home </td><td>ย้าย cursor ไปที่ต้นบรรทัด</td></tr><tr><td>Ctrl + E or End </td><td>ย้าย cursor ไปที่ปลายบรรทัด</td></tr><tr><td>Ctrl + F or Right arrow </td><td>ขยับ cursor ไปข้างหน้าโดยข้ามไปทีละคำ (word)</td></tr><tr><td>Ctrl + B or Left arrow </td><td>ขยับ cursor ถอยหลังโดยข้ามไปทีละคำ (word)</td></tr><tr><td>Ctrl + L</td><td>ล้างหน้าจอ terminal คล้ายกับคำสั่ง <code>clear</code></td></tr><tr><td>Ctrl + R</td><td>ค้นหาคำสั่งที่เคยพิมพ์มาก่อนหน้านี้</td></tr><tr><td>Ctrl + C</td><td>หยุดการทำงานของโปรแกรม</td></tr><tr><td>Ctrl + D or Delete</td><td>logout หรือออกจากคำสั่งที่กำลังทำงานอยู่</td></tr><tr><td>Ctrl + P</td><td>ค้นหาคำสั่งแบบย้อนหลัง หรือ History search (backward) </td></tr><tr><td>Ctrl + N</td><td>ค้นหาคำสั่งแบบไปข้างหน้า หรือ History search (forward) </td></tr><tr><td>TAB</td><td>เติมเต็มคำสั่งที่เคยเรียกใช้อัตโนมัติ</td></tr></tbody></table>

{% hint style="info" %}
**Basic Commands**
{% endhint %}

<table><thead><tr><th width="129.33333333333331">ชุดคำสั่ง </th><th>                       คำอธิบาย </th><th>                     ตัวอย่าง </th></tr></thead><tbody><tr><td>mkdir </td><td>ใช้สร้างไดเรกทอรี่ใหม่  </td><td><p>mkdir (ชื่อไดเรกทอรี่) </p><p>เช่น <code>mkdir test1</code> </p></td></tr><tr><td>cd </td><td>การเข้าสู่ไดเรกทอรี่ที่ต้องการ </td><td><p>cd (ไดเรกทอรี่ที่ต้องการเข้า) </p><p>เช่น <code>cd test1</code></p></td></tr><tr><td>touch</td><td>ใช้สร้างไฟล์ หรืออัพเดตเวลาการแก้ไขไฟล์ล่าสุด</td><td>touch test.txt<br><code>touch -m test.txt</code> </td></tr><tr><td>ls </td><td>แสดงไฟล์ที่อยู่ในไดเรกทอรี่ </td><td><code>ls</code> </td></tr><tr><td>cp </td><td><p>เป็นคำสั่งที่ใช้ในการคัดลอกไฟล์ </p><p>(ทั้งไฟล์เดียวและหลายไฟล์) </p><p>โดยระบุ source และ target </p></td><td><p>cp (ชื่อไฟล์) (ที่อยู่ที่ต้องการคัดลอกไฟล์ไปไว้) </p><p>เช่น <code>cp test.txt test1</code><br>คือการ copy file ชื่อ test.txt ไปไว้ในไดเรกทอรี่ test1    </p></td></tr><tr><td>mv </td><td><p>เป็นคำสั่งที่ใช้ในการโยกย้ายไฟล์<br><br>หรือ<br></p><p>เปลี่ยนชื่อไฟล์ </p></td><td><p>mv (ชื่อไดเรกทอรี่เดิม) (ชื่อไดเรกทอรี่ใหม่ที่ต้องการย้ายไป) </p><p><code>mv file.txt /test1</code><br><br>เปลี่ยนชื่อไฟล์ mv (ชื่อเก่า) (ชื่อใหม่)<br><code>mv file.txt newfile.txt</code></p></td></tr><tr><td>rm  </td><td><p>ใช้ในการลบไฟล์โดยสามารถใช้ได้ทั้ง</p><p>ไฟล์เดียวหรือหลายไฟล์ </p></td><td><p>rm (ตามด้วยชื่อไฟล์ที่ต้องการลบ) </p><p><code>rm test1.txt</code> </p></td></tr><tr><td>rmdir </td><td><p>ใช้ลบไดเรกทอรี่ ซึ่งสามารถลบได้</p><p>เฉพาะไดเรกทอรีว่างเท่านั้น </p></td><td><code>rmdir directory_name</code> </td></tr><tr><td>echo </td><td><p>เป็นคำสั่งที่ใช้ในการแสดงข้อความใดๆ</p><p>ที่ต้องการให้ถูกปรากฏบนหน้าต่างเทอร์มินัล <br>หรือสามารถใช้แทรกข้อความลงในไฟล์ได้</p></td><td><p>echo (ข้อความที่ต้องการแสดง) </p><p><code>echo Hello</code> <br><br><code>echo this is message >> test.txt</code></p></td></tr><tr><td>cat </td><td><p>ใช้แสดงข้อมูลที่อยู่ในไฟล์ออกมา</p><p>แสดงครั้งเดียวพร้อมกันทั้งหมด  ในบางครั้งก็</p><p> ใช้ในการรวมไฟล์หลายไฟล์เข้าด้วยกันมา</p><p>เป็นไฟล์เดียว และสามารถใช้สร้างไฟล์ </p></td><td><p>cat (ไฟล์.txt) </p><p>เช่น <code>cat test.txt</code> </p></td></tr><tr><td>clear</td><td>ล้าง terminal ให้อยู่ใน init state</td><td><code>clear</code></td></tr><tr><td>df </td><td><p>แสดง ผลได้ทั้งจำนวนพื้นที่ที่มีการใช้งาน</p><p>ไปแล้วในระบบ และพื้นที่ว่างที่สามารถใช้งาน </p></td><td><code>df -h</code></td></tr><tr><td>du </td><td><p>คำสั่งที่ใช้ในการตรวจสอบขนาดการใช้งาน</p><p>ไดเรกทอรีที่ชี้อยู่ (mount point) รวมถึง</p><p> ไดเรกทอรีย่อยๆลงไปจากตำแหน่งปัจจุบัน </p></td><td><code>du -h</code></td></tr><tr><td>pwd </td><td>แสดงไดเรกทอรี่ที่กำลังใช้งาน </td><td><code>pwd</code> </td></tr><tr><td>ifconfig </td><td><p>ตรวจสอบว่ากำลังใช้ Network Interface</p><p> Card (NIC) หมายเลขตัวใดอยู่ เช่น eth0 </p><p>หรือ eth1 เป็นต้น</p></td><td><code>ifconfig</code> </td></tr><tr><td>tar </td><td><p>ใช้สำหรับแตกไฟล์นามสกุล tar </p><p>และบีบอัดไฟล์หรือไดเรกทอรี่ให้เป็น</p><p>ไฟล์นามสกุล tar </p></td><td><p>tar cvf (ชื่อไฟล์.tar) (ไดเรกทอรี่หรือไฟล์ที่ต้องการบีบอัด) </p><p>เช่น <code>tar cvf test1.tar test1</code> </p><p>คำสั่งแตกไฟล์ tar </p><p><code>tar xvf test1.tar</code> </p></td></tr><tr><td>chmod </td><td><p>การกำหนดสิทธิ์ในการเข้าถึงไฟล์</p><p>โดยแบ่งสิทธิ์ไว้ 3 กลุ่มคือ Owner Group</p><p> publie ซึ่งจะแทนตัวเลข 0-7 ในการกำหนด</p><p>สิทธิ์ของแต่ละกลุ่ม เช่น  644 (เลขฐานแปด)หรือเทียบเท่ากับ rw-r--r-- หมายถึง เจ้าของอ่านและเขียนได้ แต่คนอื่น</p><p>ทั่วไปอ่านได้อย่างเดียว </p></td><td><p>chmod (กำหนดสิทธิ์การเข้าถึง) (ชื่อไฟล์) </p><p>เช่น <code>chmod 644 test</code> </p></td></tr><tr><td>uname </td><td>แสดงชื่อของระบบปฏิบัติการที่ใช้งานอยู่ </td><td><code>uname -a</code></td></tr><tr><td>ps aux </td><td><p>ใช้แสดงรายการประมวลผลต่างที่กำลัง</p><p>ทำงานอยู่ของระบบแบบระเอียด </p></td><td><code>ps aux</code> </td></tr><tr><td>kill </td><td><p>การส่งสัญญาณเข้าไปขัดจังหวะโปรเซส</p><p> เพื่อบอกกับโปรเซสตามวัตถุประสงค์ของสัญญาณ้ส่งไป สามารถดูตัวเลข  process </p><p>ได้จาก คำสั่ง kill -l </p></td><td><p>kill (ตัวเลข process) (PID) </p><p>เช่น <code>kill –9 203</code> </p></td></tr><tr><td>zip </td><td>ใช้บีบอัดไฟล์เป็นนามสกุล zip </td><td><p>zip (ชื่อไฟล์.zip) ไฟล์ที่ต้องการzip  </p><p> เช่น <code>zip test.zip test</code> </p></td></tr><tr><td>unzip </td><td>ใช้แตกไฟล์นามสกุล zip </td><td><p>unzip (ไฟล์.zip) </p><p>เช่น <code>unzip test.zip</code> </p></td></tr><tr><td>sudo su </td><td><p>ใช้เมื่อผู้ใช้ต้องการเข้าในฐานะผู้ดูแลระบบ</p><p>ที่เรียกว่า Superuser หรือ root </p></td><td><code>sudo su</code> </td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.aic-eec.com/biil_psoc6/sensor-interfacing-and-hmi/bdh-shell/shell-principles.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
