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.
|
|
06-30-2012, 10:48 PM
|
#1
|
LQ Newbie
Registered: Jun 2012
Posts: 10
Rep:
|
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.
|
|
|
06-30-2012, 10:59 PM
|
#2
|
LQ Guru
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,326
|
the first line: #!bin/bash should be #!/bin/bash
|
|
|
06-30-2012, 11:00 PM
|
#3
|
LQ Guru
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573
|
You need a "/" in front of the "bin/bash" at the beginning of your script. IE:
should be
edit: too slow....
Last edited by suicidaleggroll; 06-30-2012 at 11:02 PM.
|
|
|
06-30-2012, 11:05 PM
|
#4
|
LQ Newbie
Registered: Jun 2012
Posts: 10
Original Poster
Rep:
|
@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.
|
|
|
07-01-2012, 12:25 PM
|
#5
|
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852
|
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.
|
|
|
07-01-2012, 07:28 PM
|
#6
|
LQ Newbie
Registered: Jun 2012
Posts: 10
Original Poster
Rep:
|
@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!
|
|
|
07-03-2012, 09:28 AM
|
#7
|
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852
|
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.
|
|
|
All times are GMT -5. The time now is 02: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
|
|