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
  • 280,126
  • 43
  • 390
  • 441
Kaivalya Swami
  • 91
  • 1
  • 12

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
  • 5,332
  • 3
  • 15
  • 32