【发布时间】:2015-05-03 14:04:26
【问题描述】:
我正在尝试制作一个脚本来检查文件中是否有任何 tyext。我开发了以下脚本。我已经检查它是否正好有 2 个参数,看看文件是否存在,但我无法检查文件中的文本。代码如下:
#!/bin/ksh
#check if number of arguments are 2
if [ $# -ne 2 ]; then
echo "Does not equal two arguments"
echo "Usage $0 inputfile outputfile"
exit 1
fi
#check if input file exists
if [ ! -f $1 ]; then
echo "$1 not found!"
exit 1
fi
#Check if input file is null
#This next block of code is where the issue is
if [ grep -q $1 -eq 0 ]; then
echo "$1 must have text within the file"
exit 1
fi
任何帮助将不胜感激
【问题讨论】:
标签: unix if-statement command-line-arguments