0

I'm trying to use this command:

for i in $(cat file); do echo "$whatever_text.$i">$i; done

which is for making each line a new file, I will get straight to the point here!

I want for bash to ignore the expressions such as "$" because for example if I have a line like this:

$a = 'string';

or multiple lines like that, it won't be printed like that, bash leaves only 'string'.

chepner
  • 497,756
  • 71
  • 530
  • 681
HR.AB
  • 1
  • 1

1 Answers1

3

The correct way to iterate over the lines of a text file is to use the read command from a while loop.

while IFS= read -r i; do
    echo "$whatever_text.$i" > "$i"
done < file

See Bash FAQ 001 for more details.

chepner
  • 497,756
  • 71
  • 530
  • 681