Shell 小结和实操记录(shell与Python交互使用)

1. shell 脚本语言

首行指定解释器:#!/bin/bash

特殊字符的含义

shell 控制流

if 循环

if condition1
then
    command1
elif condition2 
then 
    command2
else
    commandN
fi

附:
1、如果else分支没有语句执行,就不要写这个else
2、末尾的fi就是if倒过来拼写,后面还会遇到类似的

写成一行(适用于终端命令提示符):if [ $(ps -ef | grep -c "ssh") -gt 1 ]; then echo "true"; fi

例子:

#!/bin/bash
a=1
b=2
if [[ $1==a && $2==b ]]
then
    echo 'This a test shell script.'
else
    echo 'Please give some paras.'

fi

输出:

This a test shell script.

for 循环

for var in item1 item2 ... itemN
do
    command1
    command2
    ...
    commandN
done

写成一行:for var in item1 item2 ... itemN; do command1; command2… done;

注:in列表是可选的,如果不用它,for循环使用命令行的位置参数,比如:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值