LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 10-03-2014, 04:17 PM   #1
jazzo
Member
 
Registered: Jul 2012
Posts: 277

Rep: Reputation: Disabled
script won't execute


Hello all,
I have just created the text1.sh script with notepad in ubuntu containing the following code:
Code:
!#/bin/bash
read -p "Enter your name: " name
echo "Hi, $name, let's be friends!"
then I changed the permissions and executed it:
Code:
antobbo@antobbo-linux-Dell-System-XPS-L702X:~/Desktop$ ./test1.sh
but whatever I type at the prompt after I click enter I receive the following message:
Code:
: No such file or directorybash
Enter your name: baost
': not a valid identifier `name
Hi, , let's be friends!
antobbo@antobbo-linux-Dell-System-XPS-L702X:~/Desktop$
I'm kind of wondering what it is that I've done wrong...any idea?
thanks
 
Old 10-03-2014, 04:28 PM   #2
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,623

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
Quote:
created the text1.sh script with notepad
???
Notepad ?
as in Microsoft's Notepad ?

then the FIRST thing you need to do is run
"dos2unix" on it to remove the MICROSOFT line endings

then you will likely need to look at it is gedit,kate,kwrite,vi,emacs,....
to make sure that it is not royally messed up from he Microsoft formatting
 
Old 10-03-2014, 05:28 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,669

Rep: Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892
And...
Quote:
!#/bin/bash
Should be
Quote:
#!/bin/bash
 
Old 10-04-2014, 04:57 AM   #4
jazzo
Member
 
Registered: Jul 2012
Posts: 277

Original Poster
Rep: Reputation: Disabled
Thanks guys:
@John VV: no not microsoft, I'm on ubuntu 12.04...but now that you say that, notepad probably runs on wine...um.
@michaelk: thanks for spotting that, apologies, I'll be more careful next time!
SO, I scrapped that file, installed emacs, done the script again and saved with a different name and now it works :-)
thanks guys for your help!
 
Old 10-04-2014, 07:44 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Please mark as SOLVED once you have a solution
 
Old 10-04-2014, 08:12 AM   #6
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Notepad saved the file as DOS format with CRLF. Bash doesn't understand that. Next time run dos2unix to clean the file.

jlinkels
 
  


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
[SOLVED] Bash/CGI script won't execute - error 500 Annielover Programming 6 07-02-2012 11:31 AM
[SOLVED] Source or Execute an external Script from shell script helptonewbie Linux - Newbie 2 08-11-2010 12:48 PM
How to execute a ssh script on Linux server from Windows through a bat script? wanna13e Programming 13 10-23-2009 02:41 AM
shell script won't execute brandnewbie Linux - Newbie 7 08-10-2004 01:30 PM
Firewall Script Won't Execute jimminy34 Linux - Security 3 02-02-2003 06:34 AM

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

All times are GMT -5. The time now is 09:44 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