Locking the contents of shell file - shell

I have scripted a program in shell and the file is executable. Now I want to put this file on a server so that all my friends can use it but at the same time I want to make it sure that they are not allowed to fiddle with the original script.
extension of file is .bash
How I can lock the script and keep it executable at the same time?
Any suggestions...
Thank you in advance.

You should use:
chmod 755 file.bash

Related

Why I am not able to run executables from shell script

I have a shell script which calls for different executables from it.
The shell script and the executables are within same directory and I am trying to run it from there. Still, on running, I get the error, "executable" not found- No file/directory exists.
What should I do???
First, You need to provide permission to the File :
chmod +x filename
Then, execute the binary file by,
./filename
The current directory is typically not in your command path, for security reasons. You need to provide the path explicitly, that is
./mycommand
instead of
mycommand
(Keep in mind, though, that this will break if you run the script from a different directly. ./mycommand is relative to the directory you run from, not the directory where the script is stored.)

Running an executable by calling it in a .sh file

I am very new to bash and using .sh files. I am trying to run the program aescrypt by calling it in a .sh file as follows (aescrypt is in the same directory as the .sh file) :
./aescrypt -e -p password file.txt
It throws the following error:
./aescrypt no such file or directory
Am I doing it wrong?
ps- I realy don't want to add it to the PATH variable as I will be using this on more than one computer that resets every day.
The location of the script is irrelevant. The thing that matters is the working directory of the process executing the script. The simplest solution really is to add aescrypt to a standard location like /bin or /usr/bin. If neither of those is acceptable, perhaps /usr/local/bin is an option. Otherwise, just use the full path of aescrypt in your script. Either hard code it, or if it is in the same directory as the script, try:
$(dirname $0)/aescrypt ...
(Note that hardcoding is more reliable, but less flexible. If you move the executable, the script will break. But using dirname will break if the script changes directory during execution.)
how about if you call the program like ./aescrypt.sh, thats the way to call an .sh programm througt the terminal
First off all, you have also to change the permissions of the file to make it executable, the way to make that is to write in the terminal, the command:
sudo chmod 765 aescrypt.sh
For that you have to be located where the file is

Xcode run script, is it possible to run only if a file changes?

I want to execute the script only when a certain file changes. Is this possible inside a run script phase? I donĀ“t see anything in the docs.
Thank you so much.
I would recommand reading http://indiestack.com/2014/12/speeding-up-custom-script-phases/ which is a great example of using this rarely known Build Phases little gem.
In Input Files of Run Script Phase, add the file to depend on. For example:
$(TARGET_BUILD_DIR)/$(PRODUCT_NAME).framework
In Output Files, add the file which the script will generate:
./SomeFile.txt
In script:
touch SomeFile.txt
Now the script will be called if SomeFile.txt is missing or is older than input file's date.

How do I run bash shell scripts in cygwin?

I have a file called butcher and at the top of this file I put #!/bin/bash. The I changed permissions like so chmod 777 butcher. however when I try to run the script by typing butcher, I get this error: -bash: butcher: command not found. I'm not sure how to fix it, please help! Thank you in advance! :D
The file would have to be on your $PATH for your system to find it and execute it. Otherwise, the entire path to the file would have to be specified.
To show your path try:
echo $PATH
To run your script, either put it in one of those locations (such as /usr/local/bin), or go to the directory butcher is located in and run ./butcher.

Can i make a shell script executable in Mac without chmod stuff?

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.

Resources