如果我的条件为真,如何在 bash 脚本中运行多个命令

sj1*_*j17 2 shell bash shell-script

a=Y
b=Y
c=Y


if condition like $a=='y' then execute all this statements******  
cat *.tar.gz | tar -xzvf - -i  
echo "5"  
tar -xvf *.tar.gz   
echo "9"  
rm -rf *.tar.gz  

elif($b=='y') condition ***   
cp $source $destination  
cp $source/conf/* $destination/conf

else (**** )
some commands
Run Code Online (Sandbox Code Playgroud)

Kus*_*nda 7

-if语句的标准形式是

if condition; then
    action
    action
    ...
elif condition; then
    action
    action
    ...
else
    action
    action
    ...
fi
Run Code Online (Sandbox Code Playgroud)

其中elifelse分支是可选的,并且可能有多个elif分支。

在你的情况下:

if [ "$a" = "y" ]; then
    cat *.tar.gz | tar -xzvf - -i  
    echo "5"  
    tar -xvf *.tar.gz   
    echo "9"  
    rm -rf *.tar.gz
elif [ "$b" = "y" ]; then
    cp "$source" "$destination"  
    cp "$source"/conf/* "$destination"/conf   
else
    some commands
fi
Run Code Online (Sandbox Code Playgroud)

我没有在这里查看您想要执行的实际命令,以及它们是否有意义。