user3023835
user3023835

Reputation: 13

How to insert a file into this code but not a string

This is the code:

#!/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

I want to substitute the $title to a file called emplist. Is it possible? And how can I do that? Thank you!

Upvotes: 0

Views: 49

Answers (2)

MBlanc
MBlanc

Reputation: 1783

You can use grep like this:

if grep -q "$search_word" emplist
then
     # $search_word was found inside the file emplist

Upvotes: 0

Balayesu Chilakalapudi
Balayesu Chilakalapudi

Reputation: 1406

add these lines in your shell script,

echo "enter file name with extension"
read fname
cat $fname

Upvotes: 1

Related Questions