Issue
Im new to bash, and I am unable to cat a file and use the pipe command on the terminal using bash.
This is what ive tried on the terminal command line
$ cat data | readlooptest
however i always get this message when i use the pipe |
-bash: readlooptest: command not found
I have a Script named readlooptest, and a data file
script contents of readlooptest
#!/bin/bash
read myLine
sum=0
for i in $myLine
do
sum=`expr $sum + $i`
done
echo "sum is: $sum"
data file contents are
6 4 4 7 7
So once the commands are entered in terminal, the output should be
$ chmod +x readlooptest
$ cat data | readlooptest
sum is : 28
However I get
-bash: readlooptest: command not found
Solution
This has nothing to do with piping or cat
. The actual problem is that you need to specify where readlooptest
is, since it's not in your PATH
. If it's in the working directory, simply add ./
to the start:
$ cat data | ./readlooptest
Answered By - wjandrea