0

I am new to linux, and i have a shell script (.sh),i want to read file and execute a command depending on the information read.

This is the content of the test.sh

#/bin/sh 
file="example.txt"
while IFS= read line
do
   #$AIRBIN/display_airgen_cfg -m R -f $line.txt $line
done <"$file"

I concatenate ".txt" in the variable "$line" because I need it for run the command. The contents of the txt file are as follows

But when i execute get the following error:

 NE mode is <R>.
.txt>. file is <prueba011
default delimiter is |.
and Dmode  R and nespaceid = 3NE mode is <R>.ssname and neclassversion
for the NE prueba011

When I do a "sh -x test.sh" get the following:

file=example.txt
IFS=
+ read line 
txt prueba011/bin/display_airgen_cfg -m R -f prueba011
NE mode is <R>.
.txt>. file is <prueba011
default delimiter is |.
and Dmode  R and nespaceid = 3IFS=nceId,neclassname and neclassversion
for the NE prueba011

Tried to make different concatenations, but this still does not work

  • Where are the contents of `example.txt`? I think you wanted to paste them. – Benjamin W. May 12 '17 at 16:33
  • `example.txt` contains DOS line endings. See http://stackoverflow.com/tags/bash/info for tips to remove them. (Presumably, the second line of the error message should be `file is `; the "reset" prior to `.txt` is the giveaway.) – chepner May 12 '17 at 16:40
  • @Benjamin W. example.txt contains the following : prueba011 – Gerardo Rodriguez May 12 '17 at 16:48
  • @chepner I thought the same but i dont have experiencie to make shell scripts.Try doing the following: $AIRBIN/display_airgen_cfg -m R -f "$line.txt $line" |tr -d "\r" but no working ! :( – Gerardo Rodriguez May 12 '17 at 16:51
  • It is `line` itself that contains the carriage return, not your script. You could simply use `${line%$'\r'}` in place of `$line`, but it would be better to fix the input file before trying to read from it. – chepner May 12 '17 at 16:54
  • @chepner Thank you very much, I could solve it by changing the header and running it in bash and not with sh :) – Gerardo Rodriguez May 12 '17 at 17:08

0 Answers0