Trigger script based on condition

Hi Guys,

I am having below code which runs based on condition, Is it possible to check condition at the time of trigger

code=$1
if [ $counter -eq 3 ];then
				nohup sh script.sh $val 1 &
			fi

I need to trigger if the $code = JP then only to trigger

nohup sh script.sh $val 1 &

My try but wanted to check in single line when i am triggering nohup script command

if [[ "${counter}" -eq 3  &&  "${code}" = 'JP' ]]; then  nohup sh script.sh $val 1 & 

What's happening? What doesn't work? Any errors / messages / misbehaviour?

No errors basically, Is it possible to achieve in the same command to check for $code condition

nohup sh script.sh $val 1 &

Is this what you are after?

[[ "${counter}" -eq 3  &&  "${code}" = 'JP' ]] && nohup sh script.sh $val 1 &
2 Likes

Will this work

code=$1
if [ $counter -eq 3 ];then
				[[ "${code}" = 'JP'  ]] && nohup sh script.sh $val 1 &
			fi
1 Like
Moderator comments were removed during original forum migration.