bash - How to store a variable with command status [shell script] -
i searching word in file through grep command. need store status in variable v1 0 or 1. how can it?
tail -n 2 test.s | grep -q "fa|"$(date "+%m/%d/%y") tail -n 2 test1.s | grep -q "fa|"$(date "+%m/%d/%y") tail -n 2 test2.s | grep -q "fa|"$(date "+%m/%d/%y")
if above searching word found variable v1 value should 0 else 1.
file content :
keytran|20160111|test.s submkeyqwqwqw|ndm|jan 11 01:34|test.s|6666666|sdgdh-rb|ltd.et.cts00.act loadstatus|thunnnb|6666666|fa|01/16/2016|01:34:57|01/16/2016 |01:37:13|load|test.s
please suggest
depending on shell, after each command execution status of previous command available in special variable: bash family $?
, csh family $status$
:
#/bin/bash tail -n 2 test.s | grep -q "fa|"$(date "+%m/%d/%y") v1=$?
or
#/bin/csh tail -n 2 test.s | grep -q "fa|"$(date "+%m/%d/%y") set v1=$status
Comments
Post a Comment