shell基础脚本
运行第一个shell程序
vim test.sh
#!bin/bash
echo "helloworld"
添加可执行权限
chmod + x test.sh
./test.sh通过相对路径进行程序的运行
#! /bin/bash
line="shixinfa"
echo $line
function add(){
echo "addmeans"
}
add
function sub(){
value=$(($1+$2))
return $value
}
sub 3 1
echo $?
x 删除当前光标下的字符
#!/bin/bash
#第一个shell小程序
echo hello world!
chmod +x hello_world.sh
./hello_world.sh
#使用环境变量
echo $PATH
#自定义变量hello
hello="hello world"
echo $hello
X+右箭头 为删除的功能
expr 10 + 3
#输出10+3
expr 10+3
#输出7
expr 10 - 3
#输出30
expr 10 \* 3
#输出3
expr 10 / 3
#输出1
expr 10 % 3
#将计算结果赋值给变量
num1=$(expr 10 % 3)
num1=10
num2=3
#输出num1 + num2=13
echo "num1 + num2=$[$num1 + $num2]"
num1=100
num2=200
if test $num1 -eq $num2
then
echo num1等于num2
else
echo num2不等于num2
fi