Command not found - macos

I am quite new to the Mac Terminal environment.
I donwloaded sqlplus (which is recognised as a UNIX executable program) and then in Terminal I do cd a few times until I arrive in the folder I put this in (\Applications\instantclient_10) in this case.
When I type 'ls' I see a listing of all the files including the sqlplus. So I would then expect to simply type at the Telnet prompt 'sqlplus' and then this would start but instead keep getting
-bash: sqlplus: command not found
This is problem one.
I have now downloaded MySQL and again, when I go to the correct folder (\Library\StarupItems\MySQLCOM) and I type 'ls' I see my files (including MySQLCOM) but when I come to try to 'run' this by simply typing 'MySQLCOM' again the message is:
-base: MySQLCOM: command not found
What am I doing wrong?
Thanks

To run binary/executables in current folder you need to prefix them with ./
./sqlplus
The idea here is that you want to force execution of local file and not run it accidentally. Imagine app that would put ls binary into it's folder and it would automatically run if did ls in that folder.

Related

Git Bash file which runs command in current directory, then opens chrome

Per the title, I'd like to have a .sh file which I can drop into a directory and then:
Run http-server (the simple node server) in the current directory
Open Chrome and point it to that server
The idea is that when I'm developing I can quickly run this bash file and see the current version of whatever html/css/javascript website I am working on. My issue is that if you run a command in a bash file, it isn't run in the current working directory, but rather in the root directory (as far as I can tell). So if I just write http-server in my file, it will run a server not in the current directory, but in ./.
To fix this, I want to cd to the directory first, and then run the script. current_dir=$(pwd) will give me something close to the current directory, but I can't put that directly into a cd command because it (1) doesn't have quotes around it, so spaces in directory names will make it not work, and (2) it starts with /C/ instead of /C:/. Can anyone advise me on how to fix this?
My current code looks as follows.
curr_dir=$(pwd)
cd $curr_dir
http-server
start chrome localhost/XXX
And, as mentioned, results in the http-server command being run in the wrong place:
Starting up http-server, serving ./
Available on:
http://192.168.56.1:8081
http://192.168.1.21:8081
http://127.0.0.1:8081
Hit CTRL-C to stop the server
e: For anyone who happens on this later, this isn't actually a problem -- see the accepted answer. I had another typo.
No; the commands you run always run in the current directory. Otherwise, if your hypothesis were correct, e.g. ls would always show the files in the root directory.
If you want to run a command which is in a different directory, you want
../relative/path/to/command
or
/absolute/path/to/command
Neither of these change the current directory of the shell. The current working directory of the process you create will remain the directory you were in when you run this command. (Even if you run it in the background and subsequently change to a different directory in your interactive shell, for example.)
If you want the command to run in the directory where the script lives on the disk, something like this can occasionally be useful.
cd "$(dirname "$0")"
but again, most of the time, you want and need your commands to run in the current directory.
(There are situations where you want a script to process data files in a fixed location, but these are rare exceptions. Until you have such a situation, consider it a bug to use cd in a shell script.)
If you have a command http-server somewhere on your PATH, just http-server will run that. You should normally not have the current directory on the PATH, but to run the binary in the current directory instead of from anywhere on the PATH, you say so:
./http-server

How do I run .sh or .bat files from Terminal?

I have a pretty basic problem here, that has happened so haphazardly to me that up until now, I've just ignored it. I downloaded tomcat web server and "Murach's Java Servlets and JSP" book is telling me to navigate to the tomcat/bin directory and start the server my typing in Terminal
$ startup
However, I get the error
-bash: startup: command not found
The relevant files in this directory are startup.sh and startup.bat. Typing both of these returns the same error message
So my questions are, what are .bat and sh files, and how do I run these files? I've read several tutorials for different languages and software programs, and some times when the tutorial says execute a bunch of files in the command line, I get a "command not found" error. Sometimes it works, sometimes it doesn't. This is perplexing to me, so what are some common solutions to solving these sort of "command not found" Terminal problems?
The .sh is for *nix systems and .bat should be for Windows. Since your example shows a bash error and you mention Terminal, I'm assuming it's OS X you're using.
In this case you should go to the folder and type:
./startup.sh
./ just means that you should call the script located in the current directory. (Alternatively, just type the full path of the startup.sh). If it doesn't work then, check if startup.sh has execute permissions.
This is because the script is not in your $PATH. Use
./scriptname
You can also copy this to one of the folders in your $PATH or alter the $PATH variable so you can always use just the script name. Take care, however, there is a reason why your current folder is not in $PATH. It might be a security risk.
If you still have problems executing the script, you might want to check its permissions - you must have execute permissions to execute it, obviously. Use
chmod u+x scriptname
A .sh file is a Unix shell script. A .bat file is a Windows batch file.
Type bash script_name.sh or ./script_name in linux terminal. Before using ./script_name make you script executeable by sudo chmod 700 script_name and type script_name.bat in windows.
Drag-And-Drop
Easiest way for a lazy Mac user like me: Drag-and-drop the startup.sh file from the Finder to the Terminal window and press Return.
To shutdown Tomcat, do the same with shutdown.sh.
You can delete all the .bat files as they are only for a Windows PC, of no use on a Mac to other Unix computer. I delete them as it makes it easier to read that folder's listing.
File Permissions
I find that a fresh Tomcat download will not run on my Mac because of file permission restrictions throwing errors during startup. I use the BatChmod app which wraps a GUI around the equivelant Unix commands to reset file permissions.
Port-Forwarding
Unix systems protect access to ports numbered under 1024. So if you want to use port 80 with Tomcat you will need to learn how to do "port-forwarding" to forward incoming requests to port 8080 where Tomcat listens by default. To do port-forwarding, you issue commands to the packet-filtering (firewall) app built into Mac OS X (and BSD). In the old days we used ipfw. In Mac OS X 10.7 (Lion) and later Apple is moving to a newer tool, pf.
Based on IsmailS' comment the command which worked for me on OSX was:
sudo sh ./startup.sh
On windows type either startup or startup.bat
On unix type ./startup.sh
(assuming you are located in tomcat/bin directory)
Batch files can be run on Linux. This article explains how (http://www.linux.org/threads/running-windows-batch-files-on-linux.7610/).
Type in
chmod 755 scriptname.sh
In other words, give yourself permission to run the file. I'm guessing you only have r/w permission on it.
add #!bin/bash on top of the your .sh file
sudo chmod +x your .sh file
./your.sh file
these steps work~
My suggestion does not come from Terminal; however, this is a much easier way.
For .bat files, you can run them through Wine. Use this video to help you install it: https://www.youtube.com/watch?v=DkS8i_blVCA. This video will explain how to install, setup and use Wine. It is as simple as opening the .bat file in Wine itself, and it will run just as it would on Windows.
Through this, you can also run .exe files, as well .sh files.
This is much simpler than trying to work out all kinds of terminal code.
I had this problem for *.sh files in Yosemite and couldn't figure out what the correct path is for a folder on my Desktop...after some gnashing of teeth, dragged the file itself into the Terminal window; hey presto!!

-bash: sencha command not found

I installed Sencha SDK and Sencha command on my mac-mini and done with some sample app.. but suddenly after some time when I tried to run sencha command on terminal, I got the response as '-bash: sencha command not found', I don't know why this was happened. Earlier I didn't find such type of response but now I got this error. Please tell me what are the possible scenarios for this thing to be happened.. Thanks for your help
Alens-Mac-mini:touch-2.2.0 SenchaTools$ sencha
-bash: sencha: command not found
You should procede that way:
Verify if this command is contained in PATH. PATH is an environment variable holded by bash and initialized when a new user is logged in (.bash_profile file for all user and the corrispective into home for single user). So check what echo $PATH told you and verify if this command is contained into those folder
Probably, from step 1, the answer will be "No, it isn't". So you have to procede this way: use whereis command to search this command (that will be an executable script) and once you find it, you have two possibilities: one is to use it directly by specifying full path (returned from whereis command).
If you want to run simply it with sencha -arguments you have to add executable path returned by whereis ($PATH=$PATH:/returned/path/by/whereis) into file .bash_profile
In that way you should be able to execute your command from any "point" in your filesystem
The Sencha installer expects you to use bash as shell. It fails, if you use any other (like the nice zsh). You need to copy the content of .bash_profile to your shell startup-file (.zprofile in my case), save it and open a new terminal window.
Add PATH and VAR manually in .bash_profile file at the root of your user folder,
export SENCHA_CMD_3_0_0="/Users/you/Path/To/Sencha/Cmd/3.0.0.XXX"
export PATH=/Users/you/Path/To/Sencha/Cmd/3.0.0.188:$PATH
Find out more about this issue at sencha forum https://www.sencha.com/forum/showthread.php?245243-Command-not-found-mac-OSX-mountain-lion

Add directory to system path in OS X Lion

I can't figure out how to add a directory to the system path. I found out that the command is something like this:
export PATH=$PATH:/my_path/to/my_dir
Example
I run the terminal in the path where my installation directory is located. In this case I'm talking about Play Framework. And I type:
export PATH=$PATH:/to/play20
It looks like nothing happens. In fact, when I type the command "play" (to execute the framework) I get:
-bash: play: command not found
Can someone please give me a decent step-by-step guide?
Execute the command “/to/play20/play help”. If this gives the expected output (help for the play command), then the executable is available, and the problem is in the shell path. If it does not give the expected output, then the executable is not working.
In the former case, ensure you are running the bash shell. (This is the default for recent versions of Mac OS X, but it may be changed for specific accounts.) To do this temporarily, execute the command “bash”. (When you want to exit the temporary shell, execute the command “exit”.) Then execute the export command again. (When the export command works, it changes the variable without displaying any output, so this is normal.) Check the spelling in the export command carefully.
In the latter case, execute “ls -ld /to/play20/play”. If you get a message that the file does not exist, then the executable is not installed correctly, and I cannot help you further. If the file is present, then it is not executable for some reason. This might be because you do not have permission to access it (especially permission to execute it, marked by “x” in certain places in the initial field of the ls output that may contain hyphens, “r”, “w”, and a few other letters) or that it is a symbolic link to a file that does not exist (indicated by an “l” in the first character of the ls output for the file). Lack of permission can be fixed by the chmod command, assuming you have appropriate permissions for changing permissions on the system. If the file is a symbolic link to another file, you may have a bad installation, or the target file may have permission issues (or be another symbolic link, and so on).

Problem setting up github repository, touch not recognized in CMD

When I get to the step:
touch README
I get the error
'touch' is not recognized as an internal or external command, operable program or batch file.
What does this mean?
I'm in Win 7 Home Premium command prompt.
Make sure you're working in git bash, not cmd.
The touch command updates the last-modified timestamp of the file to the current time, or if the file doesn't already exist, creates an empty file with the given name. This command does not exist (by default) in Windows, which is the reason you get that error message.
To get past this step, you can create a file called README in whatever way you feel most comfortable with. For example, you could use notepad.exe if you have no better alternative available.
Use this code in CMD and then touch your file
npm install touch-cli -g

Resources