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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
02-06-2017, 01:51 AM
|
#1
|
Member
Registered: Sep 2016
Location: Webster MA USA
Posts: 243
Rep:
|
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)
Last edited by L_Carver; 02-06-2017 at 01:53 AM.
Reason: attachment proved invalid
|
|
|
02-06-2017, 02:38 AM
|
#2
|
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,021
|
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.
|
02-06-2017, 02:40 AM
|
#3
|
Moderator
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,297
|
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
|
|
|
02-06-2017, 05:51 AM
|
#4
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,800
|
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.
|
|
|
02-06-2017, 07:39 AM
|
#5
|
Member
Registered: Sep 2016
Location: Webster MA USA
Posts: 243
Original Poster
Rep:
|
You clinched it.
Thanks
Quote:
Originally Posted by grail
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.
|
|
|
|
02-06-2017, 09:10 AM
|
#6
|
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,021
|
Please mark as SOLVED once you have a solution.
|
|
1 members found this post helpful.
|
All times are GMT -5. The time now is 04:54 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|