6
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
4
  • 2
    Is the question about how to write basic bash syntax? There are tons of tutorials out there ... Commented Oct 4, 2018 at 6:48
  • 1
    what i actually want is to run multiple commands if condition is true otherwise skip all those commands, in all the tutorials i am getting that u can olny run one command after if holds true. Commented Oct 4, 2018 at 6:51
  • 1
    I don't believe you looked. Here's one serverfault.com/a/216431/267016 Commented Oct 4, 2018 at 6:55
  • Possible duplicate of Correct syntax for `if...elif` statements Commented Oct 4, 2018 at 11:28

1 Answer 1

12

The standard form of an if-statement is

if condition; then
    action
    action
    ...
elif condition; then
    action
    action
    ...
else
    action
    action
    ...
fi

where the elif and else branches are optional and where there may be multiple elif branches.

In your case:

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

I have not looked at the actual commands that you want to execute here, and whether they make sense.

3

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.