我有一个执行所有命令直到到达if
语句的脚本:
脚本:
#!/bin/bash
######VARIABLES#######
#grep return value
gret=$?
######LOGIC#######
cd /home/logs
echo "Enter filename: "
read filenamex
echo "filename : ${filenamex}"
grep ${filenamex} log.dat | grep "End receiving ftp file:"
echo $?
if [ {gret} -ne 0 ]; then
echo "{filenamex} cannot be found in the recent logs. We will now check the old logs."
sleep 3
grep ${filenamex} log.dat* | grep "End receiving ftp file:"
fi
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮我执行脚本,以便如果我无法获得grep
所需的值,脚本将执行该if
语句吗?