user2342875
user2342875

Reputation: 239

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.

Upvotes: 0

Views: 199

Answers (2)

William Pursell
William Pursell

Reputation: 212268

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.)

Upvotes: 2

Adrianx002
Adrianx002

Reputation: 1

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

Upvotes: -1

Related Questions