LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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: 243

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, 20 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: Arch
Posts: 10,021

Rep: Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199
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<=15, FreeBSD_12{.0|.1}
Posts: 6,297
Blog Entries: 24

Rep: Reputation: 4255Reputation: 4255Reputation: 4255Reputation: 4255Reputation: 4255Reputation: 4255Reputation: 4255Reputation: 4255Reputation: 4255Reputation: 4255Reputation: 4255
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 Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,800

Rep: Reputation: 7568Reputation: 7568Reputation: 7568Reputation: 7568Reputation: 7568Reputation: 7568Reputation: 7568Reputation: 7568Reputation: 7568Reputation: 7568Reputation: 7568
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: 243

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: Arch
Posts: 10,021

Rep: Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199
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:54 PM.

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