LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Head scratcher - bash script returns error only once (https://www.linuxquestions.org/questions/linux-newbie-8/head-scratcher-bash-script-returns-error-only-once-4175599080/)

L_Carver 02-06-2017 01:51 AM

Head scratcher - bash script returns error only once
 
1 Attachment(s)
This snippet
Code:

echo -e "What text file will I be using?"
read -e item

returns this to stdout:
Code:

What text file will I be using?
list.txt
list.txt: command not found

but only in one script. Almost every other interactive bash script I have used that snippet in do not return such a message. Am I missing something?

Carver
(Whole script is attached)

grail 02-06-2017 02:38 AM

Your 'if' has no test included, ie the word 'test' or [[]] seem to be missing, hence the 'if' is testing the output of the command returned by $item.

As per your previous posts, the reason for the 'if' and the setting of IFS still make no sense to me, because I have still never seen a file that uses a backspaced newline as its delimiter.

astrogeek 02-06-2017 02:40 AM

I think the error is being generated by the following test, not the read itself.

Use set -xv at the top of your script to see what it is trying to do with your input.

-- @grail faster than I, as usual!

pan64 02-06-2017 05:51 AM

Code:

if  "$item" =~ ; then
is syntactically incorrect in your shell script, but I don't know if it is exactly the same....
such kind of errors can be found automatically on the page I already suggested: http://www.linuxquestions.org/questi...7/#post5665533. You do not need to wait any response, it will tell you the result immediately.
Also set -xv already mentioned several times, using it will speed up finding these issues too.

L_Carver 02-06-2017 07:39 AM

You clinched it.
 
Thanks

Quote:

Originally Posted by grail (Post 5665731)
Your 'if' has no test included, ie the word 'test' or [[]] seem to be missing, hence the 'if' is testing the output of the command returned by $item.

As per your previous posts, the reason for the 'if' and the setting of IFS still make no sense to me, because I have still never seen a file that uses a backspaced newline as its delimiter.


grail 02-06-2017 09:10 AM

Please mark as SOLVED once you have a solution.


All times are GMT -5. The time now is 06:27 PM.