0

I think this is the worst error I have ever seen. I have written what I have seen also here:

Example of script but continuously I get error. My plan is to see how read command works. But it seems a dodgy error in my code or terminal. I wondered if anyone has seen similar problem?

#!/usr/bin/bash
echo "Plz enter"
read  text
echo "You entered $text"
echo $text
echo "$text"

Error:

$ . test.sh 
Plz enter
b
': not a valid identifier
You entered 


$ 
2
  • what's the output of 'which bash' command Commented Apr 24, 2014 at 9:58
  • on linux and mac (shell) Commented Apr 24, 2014 at 9:58

3 Answers 3

2

Yes I had the same error in windows with cygwin, I fixed it changing the end of line format from windows format to unix format.

You can also convert the end of line format using Notepad++: Edit > EOL Conversion > UNIX, then save and run the file.

Sign up to request clarification or add additional context in comments.

Comments

2

Your input file contains CR+LF line endings.

Remove those and the script should work well. You could use dos2unix or any other utility to remove the CR.

5 Comments

mmm...CR + LF please give minor details for a Noob... :)
@NoobEditor The link in the answer should help, I suppose.
yup...even i found same link searcing for it!! :)
meanwhile...you never told me, how a 94 year old dev null can answer so precisly!! :D
@NoobEditor Perhaps because of the age!
0

I think, try to change the shell path as like below!

root@sathish:/tmp# vim test.sh

#!/usr/bin/bash
echo "Plz enter"
read  text
echo "You entered $text"
echo $text
echo "$text"

root@sathish:/tmp# chmod +x test.sh 
root@sathish:/tmp# ./test.sh 
-bash: ./test.sh: /usr/bin/bash: bad interpreter: No such file or directory

root@sathish:/tmp# which bash
/bin/bash

root@sathish:/tmp# ls /usr/bin/bash
ls: cannot access /usr/bin/bash: No such file or directory

root@sathish:/tmp# vim test.sh 

#!/bin/bash
echo "Plz enter"
read  text
echo "You entered $text"
echo $text
echo "$text"

root@sathish:/tmp# ./test.sh 
Plz enter
a
You entered a
a
a

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.