3

I am taking lines from a .txt file: Say Input.txt

a
*
b

Then I am reading it with:

#!/bin/bash
file=$1

ans=0
while  read -r line || [[ -n "$line" ]]
do
echo $line
done < $file # passing the file

for which I am getting the following output

a
test main.py sic.sh
b

Where files of my directory are being shown instead of *

I want to take some decisions on the basis of * char for which I need to detect/read * ?

Charles Duffy
  • 257,635
  • 38
  • 339
  • 400

1 Answers1

7

Always quote variables:

#!/bin/bash
file="$1"

ans=0
while  read -r line || [[ -n "$line" ]]
do
    echo "$line"
done < "$file" # passing the file
Poshi
  • 4,817
  • 3
  • 13
  • 28