Solved 'Command not found' even with full path

Hi,
I'm an intermediate-level user of FreeBSD. I recently ran into a problem that I have been unable to solve. Basically, most (but not all) commands now return 'Command not found', even if I use the full path, which makes no sense to me whatsoever. The only thing I can think of that happened is that I accidentally pasted some code for Apache onto the command line. In any case, I've tried quite a few things and I don't see any reason why this is happening. I am using csh.

This is the code I accidentally pasted (in case any of these may have been interpreted by csh):
Code:
curl -O < Directory "/usr/local/www/nedi/html" >
#+1445447621
AllowOverride None
#+1445447621
Require all granted
#+1445447621
Options +FollowSymLinks +ExecCGI +Indexes
#+1445447621
< /Directory >
#+1445447621
Alias /nedi /usr/local/www/nedi/html

Here are some examples demonstrating the issue:
Code:
jackd@Networks:~ % echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/home/jackd/bin
jackd@Networks:~ % which portversion
/usr/local/sbin/portversion
jackd@Networks:~ % portversion
portversion: Command not found.
jackd@Networks:~ % /usr/local/sbin/portversion
/usr/local/sbin/portversion: Command not found.
jackd@Networks:~ % sh /usr/local/sbin/portversion
/usr/local/sbin/portversion: 35: Syntax error: "(" unexpected
jackd@Networks:~ % which ls
/bin/ls
jackd@Networks:~ % ls
(RETURNS RESULTS OF LS)
jackd@Networks:~ % ls -al /usr/local/sbin/ | grep portversion
-r-xr-xr-x  1 root  wheel  9825 Dec  9  2014 portversion

Thank you for any assistance you may be able to provide
 
It depends what commands aren't working.
The first thing to note is that when running a script, 'command not found' doesn't always mean it can't find the script you are trying to run. When running a script, the system will pull the interpreter off the first (#!) line and run that program with the path of the script as the argument. If that program can't be found you will get the error you are seeing. So it's possible it is whatever program portversion is trying to run that is the problem, not portversion itself, which is why you get the error even with full path.

Have a look in the portversion code and see what script interpreter it's trying to use. That will probably get you closer to the actual cause of the problem. I may not be looking at the same portversion, but one I found on GitHub is written in ruby, which would explain the syntax error when you tried to use sh.

Of course this wouldn't explain a large number of commands not working unless they all use the same language/interpreter.

Have you tried logging out/restarting (if possible)? Sometimes it's an easy way to solve problems like this if its just something that's screwed up your current environment.
 
Logging out, yes, restarting, no. But I've got 258 days of uptime and I want to kno-ow :confused::rolleyes:. I'll just bite the bullet and kick it.
 
OK, I restarted and it didn't fix it, but I did look at the programs I was trying to run and although I thought I picked a diverse selection, they all use ruby. So looks like you're right about the script running a different binary that's having problems. I'm heading home for the day, but unless I run into anything else, I think we can consider this resolved. Thanks!
 
If the command is a script have a look at the first so-called 'she-bang' line. If that points to a non-existing interpreter (like /bin/bash for example) you will get a "command not found" error. It's not the script it cannot find, it's the interpreter.
 
Just wanted to update: I did portsnap fetch update and portmaster -a. After updating ports, I am no longer receiving the error. Thanks everyone!
 
Back
Top