Hello!
I bumped into the following problem: I'm writing a Linux batch script which does the following:
- Read line from file
- Strip the
\n
character from the end of the line just read - Execute the command that's in there
Example: commands.txt
ls
ls -l
ls -ltra
ps as
The execution of the batch file should get the first line, and execute it, but while the \n
present, the shell just outputs "command not found: ls"
That part of the script looks like this
read line
if [ -n "$line" ]; then #if not empty line
#myline=`echo -n $line | tr -d '\n'`
#myline=`echo -e $line | sed ':start /^.*$/N;s/\n//g; t start'`
myline=`echo -n $line | tr -d "\n"`
$myline #execute it
cat $fname | tail -n+2 > $fname.txt
mv $fname.txt $fname
fi
Commented you have the things I tried before asking SO. Any solutions? I'm smashing my brains for the last couple of hours over this...