LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-06-2017, 01:51 AM   #1
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 241

Rep: Reputation: Disabled
Head scratcher - bash script returns error only once


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)
Attached Files
File Type: txt noshotwell.sh.txt (811 Bytes, 19 views)

Last edited by L_Carver; 02-06-2017 at 01:53 AM. Reason: attachment proved invalid
 
Old 02-06-2017, 02:38 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,818

Rep: Reputation: 3083Reputation: 3083Reputation: 3083Reputation: 3083Reputation: 3083Reputation: 3083Reputation: 3083Reputation: 3083Reputation: 3083Reputation: 3083Reputation: 3083
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.
 
1 members found this post helpful.
Old 02-06-2017, 02:40 AM   #3
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,615
Blog Entries: 11

Rep: Reputation: 3655Reputation: 3655Reputation: 3655Reputation: 3655Reputation: 3655Reputation: 3655Reputation: 3655Reputation: 3655Reputation: 3655Reputation: 3655Reputation: 3655
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!

Last edited by astrogeek; 02-06-2017 at 02:42 AM. Reason: grail comment
 
Old 02-06-2017, 05:51 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,484

Rep: Reputation: 5530Reputation: 5530Reputation: 5530Reputation: 5530Reputation: 5530Reputation: 5530Reputation: 5530Reputation: 5530Reputation: 5530Reputation: 5530Reputation: 5530
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.
 
Old 02-06-2017, 07:39 AM   #5
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 241

Original Poster
Rep: Reputation: Disabled
You clinched it.

Thanks

Quote:
Originally Posted by grail View Post
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.
 
Old 02-06-2017, 09:10 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,818

Rep: Reputation: 3083Reputation: 3083Reputation: 3083Reputation: 3083Reputation: 3083Reputation: 3083Reputation: 3083Reputation: 3083Reputation: 3083Reputation: 3083Reputation: 3083
Please mark as SOLVED once you have a solution.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
apt-get head scratcher MaxLoad Linux - Newbie 4 04-24-2009 01:42 PM
loss of connectivity -- HEAD SCRATCHER!! alabamaman Linux - Networking 4 10-16-2007 01:44 AM
Copy Date/Time without actual files? - a real head scratcher tbeehler Linux - Software 17 07-25-2007 04:20 AM
LXer: Oracle's Linux Claims Are a Head Scratcher LXer Syndicated Linux News 0 03-23-2007 07:16 PM
virtual hosting head scratcher di11rod Linux - Networking 2 06-09-2004 02:16 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration