notes of bash
To interact with Linux, the operating system, we can use shell, a program which parses the commands we input, execute, and return the results. For the history of shell and why people interact in this way, check out this video on early days of computers by MIT.
I often think of shell as the outer "shell" while interacting the inner working kernel - operating system.
You might ask why not use mouse to click the buttons and do the similar things. Advantage of using scripts or commands to directly interact with the OS:
To get started let's ask the computer to say hello and get around with shell.
echo hello world
pwd
cd /tmp
touch a.txt
ls -al
echo "'hello!!'" > a.txt
To find the information of the commands try
help cd
, orman ls
,..
,.
are special directories represents parent folder and current folder
There are many different implementations of shell. I have been using bash and zsh. A example of using bash script is like below:
#!env bash
v1="A string"
echo "$v1 is a string, time is $(date)"
echo $@
The line started with # means it's a comment. while #! something
is a special comment about which command to execute this script. we may assign a value/string to a variable and then interpolate it into other commands.
If you need results from other commands use @ is a special variable stores all the variables given while executing this script. Try ./test.sh 1 2 3
and you will see how.
click to see details of special characters
ls -alht
to list files in directory, h for hex in file size, a for hidden files, l to list details, t to sort by recencyfind . -name "*.html" -print0 | xargs -0 zip a.zip
[1] Missing sementer shell, shell scripts