Shell learning 2

tutorial2

tutorial vidio

$

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

  • $1 - $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

  1. 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.

1
2
3
4
5
6
7
8
// mcd.sh files

mcd
{
mkdir -p "$1" //$1 is script parameter, you can set $1 - $9, $0 is script name
cd "$1"

}

this is a script

The function is to create a folder and enter the folder.

  • how do we use the script

such as

1
2
source mcd.sh //enter the script
mcd test //use the function to creat the folder

I 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

1
2
3
mkdir 111/222
sudo !!
sudo mkdir 111/222

grep

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
true
echo $?

false
echo $?

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 print

chmod

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

  • Copyrights © 2022-2024 Jessy Huang
  • Visitors: | Views:

请我喝杯咖啡吧~