Mac shell script not updating
January 20, 2015 2:13 PM   Subscribe

Ok, I'm trying to figure out shell scripting. I wrote a simple bash script, saved it in ~/bin/, made sure /bin/ was in my PATH variable, updated the permissions to make it executable and successfully executed it from Terminal. However, when I make changes to the script in BBEdit and save the changes, they don't seem to "take". When I re-run the script in Terminal, the changes don't seem to have been made. I opened new terminal windows, quit the Terminal, etc., to no avail. What am I missing?
posted by griseus to Computers & Internet (7 answers total) 1 user marked this as a favorite
 
Best answer: Use which script to show the path expects to execute when you type script. So, if that doesn't show /Users/griseus/bin/script or whatever, then you might have found the problem.

You can also try cat ~/bin/script (or whatever the path to your script is) to see if the file on disk is actually being changed by BBEdit. If not, then BBEdit is probably saving it somewhere else.
posted by Renegade Duck at 2:21 PM on January 20, 2015 [1 favorite]


saved it in ~/bin/, made sure /bin/ was in my PATH

These are different places.
posted by ryanrs at 2:46 PM on January 20, 2015 [6 favorites]


Seconding ryanrs - that jumped out at me too. Make sure your path includes ~/bin or $HOME/bin and if not, add it.

When I re-run the script in Terminal, the changes don't seem to have been made.

How are you running this? Are you in the ~/bin directory, and are you executing with the specific path? If you try
$ cd ~/bin; ./myscript.sh
does it reflect your changes?
posted by RedOrGreen at 3:04 PM on January 20, 2015


Best answer: Just to answer one basic question off the bat.

If you are editing the file you are executing then you should see the changes you make. You don't have to "reload" the script or anything to get it to work.

So if you're making changes but not seeing them in the executed script you are probably not editing the file you're actually running.

BTW get the script working first where you can run it from the command line manually (without relying on the PATH loookup) then get it in your path.
posted by bitdamaged at 3:41 PM on January 20, 2015


Response by poster: Hi everyone, thanks for the responses. I best answered the ones that directly affected my issue but I appreciate all of them.

For some reason the script was running from /usr/texbin even though I saved it to a newly created /bin directory. My next task is to figure out why the script started appearing in /usr/texbin even though I saved it elsewhere. I suspect that will be a valuable learning experience. I'm obviously neither Dr. Drang nor Kieran Healy at this point...
posted by griseus at 6:09 PM on January 20, 2015


You have to be very careful about pathnames in questions like this. /bin is a system directory, it is certainly not newly created, on OS X ~/bin is not created by default, did you mean that?

From the command line, the command echo $PATH will show you all directories searched for commands, the priority is left to right in that list. The command which filename without a directory prefix, e.g. which myfilename.sh will tell you which file will be executed, if any. If a directory is not in that list then you have to specify it explicitly, e.g. ./myscript.sh
posted by epo at 2:47 AM on January 21, 2015


Doing some poking around, it looks like /usr/texbin is the location used by some TeX installers to install some command-line tools. It sounds likely to me like the script you wrote has the same name as something in /usr/texbin, and so that's what's executing when you run the script. (Or, you accidentally saved your script there at some point.)

If you changed your path by adding something like this to your .bashrc:
export PATH="$PATH:$HOME/bin"
...try changing it to something like this instead:
export PATH="$HOME/bin:$PATH"
This will ensure that the stuff you're putting in ~/bin will get first priority.
posted by neckro23 at 7:34 AM on January 21, 2015


« Older Silly computer problem, but problematic   |   Buying Life Insurance and Funeral Insurance for... Newer »
This thread is closed to new comments.