LinuxQuestions.org
Help answer threads with 0 replies.
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 06-30-2012, 10:48 PM   #1
ismaelvc
LQ Newbie
 
Registered: Jun 2012
Posts: 10

Rep: Reputation: Disabled
Why does this simple script is not working?


Hi everyone!

I have a doubt, there is this simple script I made in arch, using nano, It worked perfectly the first time I made it, then I reinstalled my arch system, and now it doesn't work, I don't get what I am doing wrong, since I did exactly the same than the last time:

Code:
ismaelvc@toybox ~ $ nano now  

(this are the contents)
----------                                                                                                                                                                                       
#!bin/bash                                                                                                        
                                                                                                                  
# NOW!                                                                                                            
                                                                                                                  
echo "" &&                                                                                                        
date &&                                                                                                           
echo "" &&                                                                                                        
cal -3                                                                                                            
----------                                                                                                        
                                                                                                                  
ismaelvc@toybox ~ $ ls -l now                                                                                     
-rw-r--r-- 1 ismaelvc users 58 jun 30 21:23 now                                                                   
                                                                                                                  
ismaelvc@toybox ~ $ chmod +x now                                                                                  
                                                                                                                  
ismaelvc@toybox ~ $ ls -l now                                                                                     
-rwxr-xr-x 1 ismaelvc users 58 jun 30 21:23 now                                                                   
                                                                                                                  
ismaelvc@toybox ~ $ sudo mv now /usr/bin

ismaelvc@toybox /usr/bin $ file now
now: ASCII text

ismaelvc@toybox /usr/bin $ LANGUAGE=en now
bash: /usr/bin/now: bin/bash: bad interpreter: No such file or directory

ismaelvc@toybox /usr/bin $ sh now

sáb jun 30 21:19:02 CDT 2012

    mayo de 2012          junio de 2012         julio de 2012   
do lu ma mi ju vi sá  do lu ma mi ju vi sá  do lu ma mi ju vi sá
       1  2  3  4  5                  1  2   1  2  3  4  5  6  7
 6  7  8  9 10 11 12   3  4  5  6  7  8  9   8  9 10 11 12 13 14
13 14 15 16 17 18 19  10 11 12 13 14 15 16  15 16 17 18 19 20 21
20 21 22 23 24 25 26  17 18 19 20 21 22 23  22 23 24 25 26 27 28
27 28 29 30 31        24 25 26 27 28 29 30  29 30 31
As you can see it works if I use "sh", when I use chmod, it changes to a green color, meaning its executable, but file doesn't recognize it as a shell script, what to do, I have studied it various times, and I still dont get what I'm doing wrong!

thanks in advance.
 
Old 06-30-2012, 10:59 PM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,026

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
the first line: #!bin/bash should be #!/bin/bash
 
Old 06-30-2012, 11:00 PM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
You need a "/" in front of the "bin/bash" at the beginning of your script. IE:
Code:
#!bin/bash
should be
Code:
#!/bin/bash
edit: too slow....

Last edited by suicidaleggroll; 06-30-2012 at 11:02 PM.
 
Old 06-30-2012, 11:05 PM   #4
ismaelvc
LQ Newbie
 
Registered: Jun 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
@schneidz & suicidaleggroll:

lol thank you very much, how silly of me, but I honestly didn't notice that.

greetings.

Last edited by ismaelvc; 06-30-2012 at 11:07 PM.
 
Old 07-01-2012, 12:25 PM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
By the way, the "&&"s (the "and" list operator) after each command aren't really necessary here. It's effect is to link two commands together so that the trailing command only executes if the previous one exits successfully.

But all of the commands you are using are so simple and stable that they will almost never fail, and there's no harmful effect involved even if they do. Just put one command on each line and save the list operators for when you really need them.

You also don't need the "" quotes after the echo commands, as it defaults to printing a newline anyway.
 
Old 07-01-2012, 07:28 PM   #6
ismaelvc
LQ Newbie
 
Registered: Jun 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
@David the H.: Thank you very much!

Yes I have been wondering what is the difference between ";" and "&&", but I didn't know I could do it without any of them, also thanks for pointing out "echo" default behaviour, I think I need to actually read some man pages and not just "view" them! But there are just massive ammounts of linux information out there, sometimes, I get lost, or worse confused lol!
 
Old 07-03-2012, 09:28 AM   #7
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Glad to help.

";", BTW, is just the default sequencer, acting the same as a newline. When one command terminates, whatever the status, the next one is executed. It's mostly there for combining multiple commands on a single line.


As for learning scripting, and Linux use in general, it just takes time. Like all other skills it becomes easier with practice, study and experience. I was just like you 10 years ago. You actually have it easier than I did; there are better resources available now.

Here are a few useful bash scripting references:
http://mywiki.wooledge.org/BashGuide
http://mywiki.wooledge.org/BashFAQ
http://mywiki.wooledge.org/BashPitfalls
http://wiki.bash-hackers.org/scripting/newbie_traps
http://www.linuxcommand.org/index.php
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/index.html
http://www.gnu.org/software/bash/manual/bashref.html
http://wiki.bash-hackers.org/start
http://ss64.com/bash/

I particularly recommend the BashGuide, as it covers all the basics of bash scripting in a few, easy-to-read pages, along with links to lots of other helpful advice.
 
  


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
simple perl script not working vinaytp Linux - Newbie 1 06-19-2009 02:13 AM
Need help getting started simple simple shell script dhonnoll78 Programming 6 12-17-2007 06:34 PM
Simple firewall script not working for me Gates1026 Linux - Newbie 4 04-16-2004 10:40 PM
Simple php script with html form not working. sinsoush Programming 4 04-01-2004 09:02 PM
simple bash script not working. e1000 Programming 4 01-14-2004 01:09 AM


All times are GMT -5. The time now is 02:57 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration