[SOLVED] Why does this simple script is not working?
Linux - NewbieThis 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!
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.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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:
ismaelvc@toybox ~ $ nano now
(this are the contents)
echo "" &&
echo "" &&
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!
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.
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!
";", 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.