Vesnog
Vesnog

Reputation: 785

Zsh executing two commands in a row independent of success

I would like to execute two commands in a row independent of the failure or success of the previous one, so I know that || and && will not work. What can I do in this case? I would like to have the shell wait for the first command to finish if it is successful; hence ; does not work either.

EDIT: I apologize the shell would be zsh and I run a shell script sending commands to different screens as seen below:

#! /bin/zsh
### Script for running everything in screens ###
### System argument screen name suffix ###
echo You have the following screens running:
screen -ls
sigarr=(NM1 NM2 NM3 Scenario4 Scenario6)
puarr=(50PU 140PU)
lumarr=(30 300 3000)
echo Please type 1 for 50PU samples and 2 for 140PU samples
read PU
if [[ $PU -ne 1 && $PU -ne 2 ]] ; then
    echo You have to enter 1 or 2
    return 1
fi

echo Please type 1 for 300fb-1 and 2 for 3000fb-1
read lum

if [[ $lum -ne 1 && $lum -ne 2 ]] ; then
    echo You have to enter 1 or 2
    return 1
fi

if [ $PU = 1 ]; then
    let "lum = $lum + 1"
    #echo $lum
fi

ex NEWrunReader.py  <<EOEX
  :43s/Lumi.*/Lumi=$lumarr[lum]/
  :x
EOEX

echo Compiling the reader file!!!
root -l << EOF
.L readerSummerStd.C+
EOF

if [ $PU = 2]; then
    let "lum = $lum + 1"
fi

echo Press any key to proceed or Ctrl+C to abort!
read 


for sigind in $sigarr
do
    screen -dmS "${sigind}_${lumarr[lum]}_${puarr[PU]}_${1}" 
    sleep 0.1
    screen -S "${sigind}_${lumarr[lum]}_${puarr[PU]}_${1}" -p 0 -X stuff "./NEWrunReader.py SummerStd $puarr[PU]_$sigind $1 >& "${sigind}_${lumarr[lum]}_${1}".txt &;exit"$'\r'
done
return 0

Upvotes: 1

Views: 4934

Answers (2)

SlippyMcSlipperson
SlippyMcSlipperson

Reputation: 31

for zsh, especially on a mac, it's ; try it from the terminal

sleep 3 ; echo "hello"

There will be a 3 seconds delay then it will print hello

Upvotes: 3

dganesh2002
dganesh2002

Reputation: 2220

Use | or & instead of usng || or &&

Upvotes: 2

Related Questions