Answer the question
In order to leave comments, you need to log in
How to read a file line by line in bash?
I'm learning bash. I'm trying to create symlinks to files, but I'm getting the following error:
ln: unable to access '/usr/share/nginx/html/blabla.txt'$'\r': No such file or directory
Add ' to the end of the line $'\r'.
What is \r is understandable, but where does the dollar come from and how to get rid of them?
The code:
while read str
do
$(ln /usr/share/nginx/html/$str /usr/share/nginx/html/tst/$str)
done < /home/user/list.txt
Answer the question
In order to leave comments, you need to log in
Solved the problem like this:
while read str; do
str=${str/'\r'/}
ln "/usr/share/nginx/html/$str" "/usr/share/nginx/html/tst/$str"
done < /home/user/list.txt
It is not necessary to use screw EOL. In nix EOL = \n, and in Windows EOL = \r\n
this is due to editing linux files from under windows / macos
for conversion there are special utilities in linux - these are dos2unix / mac2unix and unix2dos / unix2mac reverse them
p.s.
$() is superfluous here, and it is advisable to quote unknown paths, otherwise a line with a space will suddenly come across:
while read str; do
ln "/usr/share/nginx/html/$str" "/usr/share/nginx/html/tst/$str"
done < /home/user/list.txt
The problem should be solved like this:
dos2unix /home/user/list.txt
while read; do
ln -s "/usr/share/nginx/html/$REPLY" "/usr/share/nginx/html/tst/$REPLY"
done < /home/user/list.txt
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question