ln Link is not created when used IFS=read variable for pathname

29 Views Asked by At

I want to apply a link to a specific file automatically with a Linux bash script. A part of the target pathname is shall be taken from a txt file. This is my program:

bandA="B01"
while IFS= read -r bandB || [ -n "$p" ]
do
  printf '%s\n' $bandA                #from header
  printf '%s\n' $bandB                #from list.txt
  ln -sfn /bst.$bandA.cfg /bst.cfg
done < LIST.txt

The first line of LIST.txt is "B01", too. (without quotation marks)

The command line returns always

B01 B01

The problem occurs at the ln command. When I apply $bandA the link is created successfully. When I apply $bandB from the IFS=read the link is not created. Although the variable is obviously written correctly. It must be an issue with the syntax. How can I solve the issue?

1

There are 1 best solutions below

0
kaefer On

The problem was caused because some symbols were added during read process:

bst."B01'$'\r''.cfg

By deleting them with

bandB=${bandB//$'\r'/}

the link can be created.