User interface for accessing the operating system's services.
(I got that from wikipedia)
Another simple way to put it is:
- A program that takes in user input and has the OS perform the tasks.
This is the most basic it can get, not used as much, but still used in someplaces.
Places I have seen it used before:
This is what most are familar with
Bourne again shell
- Very similar to shell with some more added features.
- Since it has been made freely available for everyone, it has become a standard that a lot of people use.
It is an "upgraded" version of bash, with some feature built in improvements, i.e. tab complete commands.
Here are some notable frameworks that make it easier to use:
This is similar to zsh, but a lot of the customization is already done for you.
There are a lot more but these are the more "popular" ones that I am aware of, there are also:
We will talk about how we can start using these shells or rather what kind of information we can get.
'#!/bin/sh'
What is it?
#!
shebang
hashbang
poundbang
hashpling
(I also pulled these from wikipedia)
#!
Basicly says which interpreter to use.
#!/bin/bash
#!/bin/sh
#!/bin/csh
#!/usr/bin/perl
#!/path/to/interpreter
When trying to run a script (./scriptname) you are usually unable to run it at first.
The reason being, you usually don't have permission to.
ls
CCLulu∴~/workspace/shell-basics⨕master⚡
⤕ ls
CONTRIBUTING.md Gruntfile.js LICENSE README.md bower.json css demo.html index.html js lib node_modules package-lock.json package.json plugin res
ls -la
CCLulu∴~/workspace/shell-basics⨕master⚡
⤕ ls -la
total 496
drwxr-xr-x 21 Cuahuc staff 672 Feb 5 13:24 .
drwxr-xr-x 44 Cuahuc staff 1408 Feb 5 09:44 ..
-rw-r--r--@ 1 Cuahuc staff 8196 Feb 5 13:08 .DS_Store
drwxr-xr-x 12 Cuahuc staff 384 Feb 5 13:09 .git
-rw-r--r-- 1 Cuahuc staff 142 Feb 5 07:48 .gitignore
-rw-r--r-- 1 Cuahuc staff 75 Feb 5 07:48 .travis.yml
-rw-r--r-- 1 Cuahuc staff 1062 Feb 5 07:48 CONTRIBUTING.md
-rw-r--r-- 1 Cuahuc staff 3749 Feb 5 07:48 Gruntfile.js
-rw-r--r-- 1 Cuahuc staff 1103 Feb 5 07:48 LICENSE
-rw-r--r-- 1 Cuahuc staff 226 Feb 5 08:27 README.md
-rw-r--r-- 1 Cuahuc staff 512 Feb 5 07:48 bower.json
drwxr-xr-x 6 Cuahuc staff 192 Feb 5 07:48 css
-rw-r--r-- 1 Cuahuc staff 16240 Feb 5 07:48 demo.html
-rw-r--r-- 1 Cuahuc staff 7828 Feb 5 13:24 index.html
drwxr-xr-x 4 Cuahuc staff 128 Feb 5 08:28 js
drwxr-xr-x 5 Cuahuc staff 160 Feb 5 07:48 lib
drwxr-xr-x 466 Cuahuc staff 14912 Feb 5 07:51 node_modules
-rw-r--r-- 1 Cuahuc staff 182915 Feb 5 07:51 package-lock.json
-rw-r--r-- 1 Cuahuc staff 1066 Feb 5 07:48 package.json
drwxr-xr-x 11 Cuahuc staff 352 Feb 5 07:48 plugin
drwxr-xr-x 4 Cuahuc staff 128 Feb 5 09:19 res
Why do this?
-rw-r--r-- 1 Cuahuc staff 7828 Feb 5 13:24 index.html
drwxr-xr-x 4 Cuahuc staff 128 Feb 5 08:28 js
Let's break it down
r w x
1 1 1 = 7
1 1 0 = 6
1 0 1 = 5
1 0 0 = 4
0 1 1 = 3
0 1 0 = 2
0 0 1 = 1
0 0 0 = 0
User Group World
rwx rwx rwx
r w x | r w x | r w x
1 1 1 | 1 1 1 | 1 1 1 = 777
1 1 1 | 1 0 1 | 1 0 1 = 755
1 1 1 | 1 0 0 | 1 0 0 = 744
-rw-r--r-- 1 Cuahuc staff 7828 Feb 5 13:24 index.html
drwxr-xr-x 4 Cuahuc staff 128 Feb 5 08:28 js
r w x | r w x | r w x
1 1 1 | 1 0 1 | 1 0 1 = 755
1 1 0 | 1 0 0 | 1 0 0 = 644
Changing permissions
A simple command to change your file's permission:
chmod 777 filename.sh
chmod 755 filename.sh
chmod 744 filename.sh
Great, but how do I run it from anywhere?
Put in the PATH!
Is the place where your OS looks for where to run the binary
echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/localadmin/bin:/Users/cuahuctemocosorio/bin:/Users/cuahuctemocosorio/go/bin
Last bit, some keyboard short cuts.
ctrl + a // jump to the beginning of the line
ctrl + e // jump to the end of the line
ctrl + u // clear the current line
ctrl + w // clear one word behind the cursor
ctrl + l // clear the terminal screen
ctrl + n // same as up arrow
ctrl + p // same as down arrow
ctrl + f // move forward one character
ctrl + b // move back one character