shell01

---恢复内容开始---

#!/bin/bash

for ((i= 1;i < 3;i= i+1))
do
echo $i;

echo "$i";
done

while [ $i -lt 6 ]
do
i=$(( $i+1 ))
echo $i
done
#set + H
echo "hello world !"
printf "hello world !\n"
for skill in Ada Coffe Action Java;
do
echo "I am good at ${skill}Script"
done

ln -s item link 硬连接

单引号

 

单引号字符串的限制:

  • 单引号里的任何字符都会原样输出,单引号字符串中的变量是无效的;
  • 单引号字串中不能出现单引号(对单引号使用转义符后也不行)。

双引号

your_name='qinjx'
str="Hello, I know your are \"$your_name\"! \n"

双引号的优点:

  • 双引号里可以有变量
  • 双引号里可以出现转义字符

cat - Concatenate files
● sort - Sort lines of text
● uniq - Report or omit repeated lines
● grep - Print lines matching a pattern
● wc - Print newline, word, and byte counts for each file
● head - Output the first part of a file
● tail - Output the last part of a file
● tee - Read from standard input and write to standard output and files

 

For Mathematics, use following operator in Shell Script

Mathematical Operator in  Shell Script  Meaning Normal Arithmetical/ Mathematical Statements But in Shell
      For test statement with if command For [ expr ] statement with if command
-eq is equal to 5 == 6 if test 5 -eq 6 if [ 5 -eq 6 ]
-ne is not equal to 5 != 6 if test 5 -ne 6 if [ 5 -ne 6 ]
-lt is less than 5 < 6 if test 5 -lt 6 if [ 5 -lt 6 ]
-le is less than or equal to 5 <= 6 if test 5 -le 6 if [ 5 -le 6 ]
-gt is greater than 5 > 6 if test 5 -gt 6 if [ 5 -gt 6 ]
-ge is greater than or equal to 5 >= 6 if test 5 -ge 6 if [ 5 -ge 6 ]

NOTE: == is equal, != is not equal.

For string Comparisons use

Operator Meaning
string1 = string2 string1 is equal to string2
string1 != string2 string1 is NOT equal to string2
string1 string1 is NOT NULL or not defined 
-n string1 string1 is NOT NULL and does exist
-z string1 string1 is NULL and does exist

Shell also test for file and directory types

Test Meaning
-s file    Non empty file
-f file    Is File exist or normal file and not a directory 
-d dir     Is Directory exist and not a file
-w file   Is writeable file
-r file    Is read-only file
-x file    Is file is executable

Logical Operators

Logical operators are used to combine two or more condition at a time

Operator            Meaning 
! expression Logical NOT
expression1  -a  expression2 Logical AND
expression1  -o  expression2 Logical OR
posted @ 2017-07-24 09:15  never_comparison  阅读(148)  评论(0编辑  收藏  举报