Shell learning 2
[tutorial2](https://missing.csail.mit.edu/2020/shell-tools/)
$
we can use the $ to determin something
Such as
foo=bar
echo "value is $foo"
there would be print value is bar , warning!!: there only can use "" double quoting, dont use '' single quoting.
$0 script name
9 parameter in script
$_ used the script last command in last argument
$? Return code of the previous command
True is 0
False is 1
vim
vim is a programme’s text editor
if we are in the Vim command,there would be three mode we would have
- command mode 2. Insert mode 3. last line mode
they would show what mode we use on the buttom.
esc we can back to normal command line, so now we can wirte the command to quit and save file
Such as
:wq is save file and quit
the detail of command we can man vim or vim --help or :help in the vim
but we usually not use it, we can use code to edit text, which is VS code software shell command.
such as
vim mcd.sh
code mcd.sh
those are same function.
// mcd.sh files
mcd{mkdir -p "$1" //$1 is script parameter, you can set $1 - $9, $0 is script namecd "$1"
}this is a script
The function is to create a folder and enter the folder.
- how do we use the script
such as
source mcd.sh //enter the scriptmcd test //use the function to creat the folderI think use the vscode is easy to edit if we have.
rmdir
Remove directory
such as
rmdir test //remove test folder
mkdir test //creat test folder
!!
!! is mean can return the last command before you used it.
such as
mkdir 111/222sudo !!sudo mkdir 111/222grep
It is used to search text and strings in a given file.
such as
grep foobar mcd.sh // which means search foobar in the mcd.sh file.
If not found foobar in the file, then echo $?, it would return 1
Excuse some example
trueecho $?
falseecho $?
false || echo "Oops fail" //First one is error,so jump to second command to excute it#Oops fail
ture || echo "will be not be printed" //First one is not error, so there would not jump to second one and print it.
ture && echo "Things went well" //First one is noterror, then keep going to print the echo.#Things went well
false && echo "This will not print" //which one is error ,then all not going.
false ; echo "This will always print" //Whatever you change, it always would excute.#This will always printchmod
This command can change the file permission
rwx r is read, w is wirte , x is excute .
such as if you want to add read permission to your file, you just need to type,
chmod +r myfilename.txt
or
chmod -r myfilename.txt
chmod [command].. filename
ln
Creat shoutcut command, you can make a symbolic link for your files.
ln -s is creat the shoutcut command,
such as ln -s /application/myapp
file
File command determine what type of data is within a file
Such as
file hellow.txt