Hikerpig's wiki
T

shell

Related: [[terminal]]

常见 Bash 写法

判断上个任务是否成功

if [[ $? -ne 0 ]]; then
    echo "faild"
else
    echo "success"
fi

使用 bool 值

bool=true
if [[ "$bool" = true ]]; then
if [[ "$bool" = "true" ]]; then
if [[ "$bool" == true ]]; then
if [[ "$bool" == "true" ]]; then
if test "$bool" = true; then
if test "$bool" = "true"; then

判断变量是否存在

#!/bin/bash
#emptyEnviroment.sh
if [ $ORACLE_HOME ];then
	echo "ORACLE_HOME = $ORACLE_HOME"
else
	echo "ORACLE IS NOT EXISTS"
fi
Show Graph Visualisation