[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/skywalkerdll/JavaGuide/master/docs/operating-system/Shell.md [Back]  [Original]



- [Shell ](#shell-)
  - [ Shell ](#-shell-)
    - [Shell](#shell)
    - [ Shell](#-shell)
    - [Shell  Hello World](#shell--hello-world)
  - [Shell ](#shell-)
    - [Shell ](#shell-)
    - [Shell ](#shell-)
    - [Shell ](#shell-)
    - [Shell ](#shell-)
  - [Shell ](#shell-)
    - [](#)
    - [](#)
    - [](#)
    - [](#)
    - [](#)
    - [](#)
  - [shell](#shell)
    - [if ](#if-)
    - [for ](#for-)
    - [while ](#while-)
  - [shell ](#shell-)
    - [](#)
    - [](#)
    - [](#)


# Shell 

##  Shell 

### Shell

 Shell 

 Shell Linux Shell shell

LinuxShellPython

ShellITshellPython webShell

 shell  Shell 

![shell](http://my-blog-to-use.oss-cn-beijing.aliyuncs.com/18-11-16/60190220.jpg)

###  Shell

ShellLinux


W3Cschool  Shell
![ Shell](http://my-blog-to-use.oss-cn-beijing.aliyuncs.com/18-11-26/19456505.jpg)


### Shell  Hello World

HelloWordshellShell Hello World


(1) helloworld.sh :`touch helloworld.sh` shshShell php  shell  php 

(2) `chmod +x helloworld.sh`

(3)  vim helloworld.sh`vim helloworld.sh`(vim ------>----->------>i-----> ------->Esc----->:wq/q! wqq!)

helloworld.sh 

```shell
#!/bin/bash
#shell,echo linux
echo  "helloworld!"
```

shell # **shell #! shell linuxbash shellshell zshdash...bash shell**


(4) :`./helloworld.sh`  `./helloworld.sh`  `helloworld.sh`  `helloworld.sh` linux  PATH  helloworld.sh  /bin, /sbin, /usr/bin/usr/sbin  PATH  PATH  `helloworld.sh` `./helloworld.sh` 

![shell Hello World](http://my-blog-to-use.oss-cn-beijing.aliyuncs.com/18-11-16/55296212.jpg)


## Shell 

### Shell 


**Shell**

1. **:**  Shell  Shell 
2. **Linux** $PATH, $HOME ...,  `env` set
3. **Shell** Shell Shell Shell  Shell 

**:**
> PATH shell 
HOME  
HISTSIZE 
LOGNAME  
HOSTNAME 
SHELL Shell 
LANGUGE  
MAIL 
PS1root#$

** Linux **

`echo $HOME`Shell `echo $SHELL`

****

```shell
#!/bin/bash
#hello
hello="hello world"
echo $hello
echo  "helloworld!"
```
![](http://my-blog-to-use.oss-cn-beijing.aliyuncs.com/18-11-17/19835037.jpg)


**Shell **


- _
- _
- 
- bashhelp


### Shell 

shellJava

****

```shell
#!/bin/bash
name='SnailClimb'
hello='Hello, I  am '$name'!'
echo $hello
```


```
Hello, I am SnailClimb!
```

****

```shell
#!/bin/bash
name='SnailClimb'
hello="Hello, I  am "$name"!"
echo $hello
```



```
Hello, I am SnailClimb!
```


### Shell 

****

```shell
#!/bin/bash
name="SnailClimb"
# 
greeting="hello, "$name" !"
greeting_1="hello, ${name} !"
echo $greeting  $greeting_1
# 
greeting_2='hello, '$name' !'
greeting_3='hello, ${name} !'
echo $greeting_2  $greeting_3
```



![](http://my-blog-to-use.oss-cn-beijing.aliyuncs.com/18-11-17/51148933.jpg)


****

```shell
#!/bin/bash
#
name="SnailClimb"
# 
echo ${#name} # 10
# 
expr length "$name";
```

:
```
10
10
```

 expr :

```shell
expr 5+6    //  5+6
expr 5 + 6       //  11
```
`\`

```shell
expr 5 * 6       // 
expr 5 \* 6      // 30
```

**:**




```shell
# 1  10 
str="SnailClimb is a great man"
echo ${str:0:10} #:SnailClimb
```



```shell
#!bin/bash
#author:amau

var="http://www.runoob.com/linux/linux-shell-variable.html"

s1=${var%%t*}#h
s2=${var%t*}#http://www.runoob.com/linux/linux-shell-variable.h
s3=${var%%.*}#http://www
s4=${var#*/}#/www.runoob.com/linux/linux-shell-variable.html
s5=${var##*/}#linux-shell-variable.html
```

### Shell 

bash Shell /


```shell
#!/bin/bash
array=(1 2 3 4 5);
# 
length=${#array[@]}
# 
length2=${#array[*]}
#
echo $length #5
echo $length2 #5
# 
echo ${array[2]} #3
unset array[1]# 1
for i in ${array[@]};do echo $i ;done #  1 3 4 5 
unset arr_number; # 
for i in ${array[@]};do echo $i ;done # 
```


## Shell 

> 

 Shell 

- 
- 
- 
- 
- 

### 

![](http://my-blog-to-use.oss-cn-beijing.aliyuncs.com/18-11-22/4937342.jpg)



```shell
#!/bin/bash
a=3;b=3;
val=`expr $a + $b`
#Total value : 6
echo "Total value : $val"
```


### 



![shell](http://my-blog-to-use.oss-cn-beijing.aliyuncs.com/18-11-22/64391380.jpg)

shellscore=100AB

```shell
#!/bin/bash
score=90;
maxscore=100;
if [ $score -eq $maxscore ]
then
   echo "A"
else
   echo "B"
fi
```



```
B
```

### 

![](http://my-blog-to-use.oss-cn-beijing.aliyuncs.com/18-11-22/60545848.jpg)



```shell
#!/bin/bash
a=$(( 1 && 0))
# 0110
echo $a;
```

### 


![](http://my-blog-to-use.oss-cn-beijing.aliyuncs.com/18-11-22/93961425.jpg)



### 

![ ](http://my-blog-to-use.oss-cn-beijing.aliyuncs.com/18-11-22/309094.jpg)



```shell

#!/bin/bash
a="abc";
b="efg";
if [ $a = $b ]
then
   echo "a  b"
else
   echo "a  b"
fi
```


```
a  b
```

### 

![](http://my-blog-to-use.oss-cn-beijing.aliyuncs.com/18-11-22/60359774.jpg)

`file="/usr/learnshell/test.sh"` `if [ -r $file ]` `-w $file`

## shell

### if 

 if else-if else 

```shell
#!/bin/bash
a=3;
b=9;
if [ $a -eq $b ]
then
   echo "a  b"
elif [ $a -gt $b ]
then
   echo "a  b"
else
   echo "a  b"
fi
```



```
a  b
```

 shell  if  Java  PHP  if shell  if 

### for 

 for  for 

****

```shell
for loop in 1 2 3 4 5
do
    echo "The value is: $loop"
done
```

** 10 **

```shell
#!/bin/bash
for i in {0..9};
do 
   echo $RANDOM;
done
```

**15:**

 shell  $, for  (()) ,

```shell
#!/bin/bash
for((i=1;i

Web Proxy Viewer  |  New URL  |  Original Page