StaticDet5
Posts: 21
Joined: Sun Nov 25, 2012 5:11 am

New scripts not running

Fri Mar 21, 2014 3:27 am

I'm relatively experienced with linux, but I guess not THIS linux. I'm running Occidentalis from Adafruit. I'm trying to set up some of my "go to" commands.

I'm creating simple commands the way that I do at work:

Code: Select all

nano (command)
I put in my simple codes (The really simple ones are just directory changes so I can jump quickly. A single "cd /sys/etc/whatever").
Save it.
chmod it.

Then I go to execute it and nothing happens. No "file not found", nothing.

I put a line of gobbledygook (literally) into the script, save it, and try to run it. Nothing. No errors or anything.
The system is seeing the script, but it isn't executing it.

What am I missing here?
Thanks!

User avatar
joan
Posts: 14193
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: New scripts not running

Fri Mar 21, 2014 6:52 am

Where are you putting the commands?

How do you invoke the commands?

What (precisely) does the system respond?

StaticDet5
Posts: 21
Joined: Sun Nov 25, 2012 5:11 am

Re: New scripts not running

Fri Mar 21, 2014 11:49 am

I've tried the commands in a couple of different locations. First in my home directory, then in /bin, then in the root directory. Nothing is working.

To invoke the command I'm simply typing the name of the command. As an example, I want a command that will immediately jump me to the /bin directory.
I type in

Code: Select all

nano bin
The nano text editor comes up. I type in

Code: Select all

cd /bin
I save the file.
Once out of the editor I type

Code: Select all

chmod 777 bin
To invoke the script I type

Code: Select all

bin
I get the equivalent of a carriage return, just like if I had hit the "Enter" key, with no command.
If the command wasn't recognized as a command, I should get:
"-bash: bin: command not found"
I don't get that. I simply get a duplicate of my bash prompt. No error, no changing of the directory.

I haven't modified the basic Occidentalis install except for an apt-get update when I first set it up.
Thanks.

hk1963
Posts: 25
Joined: Fri Dec 06, 2013 6:06 pm

Re: New scripts not running

Fri Mar 21, 2014 11:59 am

Try ./bin
in the directory where you stored the bin-script.
The PATH-variable usually doesn't (and shouldn't) contain . so if you want to run a script that isn't in a directory that is not in your PATH, you've always to give the path to it.
You can see what your path is by giving the command

echo $PATH

at the prompt.
Last edited by hk1963 on Fri Mar 21, 2014 12:00 pm, edited 1 time in total.

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: New scripts not running

Fri Mar 21, 2014 11:59 am

Your script is lacking a "shebang" furthermore you cannot simply "cd" inside a script because once it's finished and control is returned to the console your original working directory is restored.

Code: Select all

#!/bin/bash
cd /bin
echo -n "my current directory is:" 
pwd
If you want to create commands that take you to specific directories then create a bash alias definition: sudo nano $HOME/.bashrc and add your lines
i.e. for a cow command use alias cow='apt-get moo'
or for bin use alias bin='cd /bin'
save the file and then logout / login for changes to take effect.

Richard S.

StaticDet5
Posts: 21
Joined: Sun Nov 25, 2012 5:11 am

Re: New scripts not running

Fri Mar 21, 2014 12:10 pm

You're absolutely right!

Is this a Debian versus "other linux" thing? At work I have several bash scripts as I have written them (I started out with shebangs in my scripts, but found that they didn't appear to change my scripts behavior here). Is this a different flavor of bash?

I'm laughing at this "fail" of mine. If I had jumped to my complex task of polling the (three DS18B20) temperature sensors, it would have worked perfectly. I almost did this, but took some time to "set things up" on the Pi so that it was a little more familiar to me. What should have taken 20 minutes has now spanned several days of off and on attempts, questions of sanity, and at least one midnight wake-up to try an idea.

If I had just cut corners, and done the project, I would have been done... :lol:

Thank you tons! You've started me on my way to a nice end of an otherwise difficult week.

Return to “Beginners”