I want to make a shell script, which is executed when it is clicked on. I know you can do this with the Terminal command chmod u+x (filename) but I want to be able to send the file let's say by email or scp, and it should still be executed when clicked on by the new user.
I don't really think that is possible. The executability of the file is not an attribute within the file which tells the system to execute it. Its something you tell the system to do. I guess it is a security measure, regarding running maybe a risky command, lets say, rm -rf an important system folder.
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!!
In the "Run Script" build phase of my project, everything works if I type in the script into the text box for "run script" in build phases.
But to make editing / diffing etc easier, I thought I would save the script as a file as part of my project, and just fill in the path in the text box instead:
Eg: I paste the following path in the text box.
/Users/superman/Documents/Projects/SomeProject/scriptname.sh
But when I try to build this, I get a "Permission Denied" message.
What can I do to fix this? If I cut/paste the actual code, then it just "works". My user account is an administrator account. No one else uses my machine.
You can simplify your Xcode project file a little further and not require the "bin/sh " in front of the script name.
To avoid this, you need to turn on "execute" permissions for users (Xcode in this case) of the file.
Steps
Go into terminal
Navigate to where your script is
run chmod 755 yourScriptName.sh
Put /bin/sh in front of the path to the script name.
/bin/sh /Users/superman/Documents/Projects/SomeProject/scriptname.sh
Just use
chmod u+x nameofscript.sh
Thats it .
Simple Steps:
Go to the <your_Script>.sh via cd <Your_Path_To_.sh_File>
Run chmod +x <your_file>.sh
Thats it
Here is what I get when I try to build my Xcode project:
Intermediates/demo2.build/Debug-iphonesimulator/demo2.build/Script-5E564EAC1393823C00BFBA83.sh
/Users/ssbarnea/Library/Developer/Xcode/DerivedData/demo2-fdzrmxojwtekcbeivraccjjadvqz/Build/Intermediates/demo2.build/Debug-iphonesimulator/demo2.build/Script-5E564EAC1393823C00BFBA83.sh: line 2: ${PROJECT_DIR}/local-deploy.sh: No such file or directory
In Xcode I added to the default arget a new Build Phase, a "Run Script" that runs with shell /bin/sh and contains only:
'${PROJECT_DIR}/local-deploy.sh'
I can assure you that the local-deploy.sh file exists in the project directory and that it is executable. It even works if I call it from the console ;)
It should be the following. s/'/"/g :-)
"${PROJECT_DIR}/local-deploy.sh"
Bourne Shell Tutorial - Strong versus weak quoting
Well, I don't think that replacing this will work. You need just put OpenCV.framework folder in proper project folder and I think that is it. I tried out and it worked.
I have seen that i can use chmod +x command in Mac to make a shell script executable. This works fine, but i have noticed that i have to do the same thing every time this shell script file is copied to another Mac computer.
Is there a way to make the shell script executable by default when double clicked, without such command ... As the shell script file will be given to many users, and doing this will be hard for some of them ?
Best regards.
If you pack your whole program in a .tar file (or in a .tar.gz-file, which is the same, but compressed), the executable-"permission" will be preserved.
Give it the '.command' extension and it can be executed from the Finder.