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 MeaningNormal Arithmetical/ Mathematical StatementsBut in Shell
   For test statement with if commandFor [ expr ] statement with if command
-eqis equal to5 == 6if test 5 -eq 6if [ 5 -eq 6 ]
-neis not equal to5 != 6if test 5 -ne 6if [ 5 -ne 6 ]
-ltis less than5 < 6if test 5 -lt 6if [ 5 -lt 6 ]
-leis less than or equal to5 <= 6if test 5 -le 6if [ 5 -le 6 ]
-gtis greater than5 > 6if test 5 -gt 6if [ 5 -gt 6 ]
-geis greater than or equal to5 >= 6if test 5 -ge 6if [ 5 -ge 6 ]

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

For string Comparisons use

OperatorMeaning
string1 = string2string1 is equal to string2
string1 != string2string1 is NOT equal to string2
string1string1 is NOT NULL or not defined 
-n string1string1 is NOT NULL and does exist
-z string1string1 is NULL and does exist

Shell also test for file and directory types

TestMeaning
-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 
! expressionLogical NOT
expression1  -a  expression2Logical AND
expression1  -o  expression2Logical OR

转载于:https://www.cnblogs.com/fanchaostudy/p/7227179.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值