这是代码:
#!/bin/bash
title='Unix Shell Programming'
read search_word
if [[ $title =~ $search_word ]]
then
echo Yes - matchli
else
echo No - match
enter code here
fi
我想将$title
替换为名为emplist的文件。可能吗?我怎么能这样做?谢谢!
答案 0 :(得分:1)
在shell脚本中添加这些行,
echo "enter file name with extension"
read fname
cat $fname
答案 1 :(得分:0)
您可以像这样使用grep
:
if grep -q "$search_word" emplist
then
# $search_word was found inside the file emplist