'Command not found (chmod +x mybinary) in 'script.sh' [duplicate]
I'm trying to make a bash script that checks if a binary has the executable bit and if it doesn't, it automatically adds it.
When i execute the script i get the following error: script/repair.sh: 37: chmod: not found.
Here is the code:
PATH="/my/path/"
BIN="mybin"
if chmod +x $PATH$BIN != -1; then
echo "Added the executable bit to '$BIN'"
else
echo "Couldn't add the executable bit to '$BIN'"
fi
Solution 1:[1]
You are changing the value of "PATH" which is a shell environment variable used to search / execute files so it can no longer find the bin chmod.
#!/bin/bash
P="/home/user/"
BIN="a.out"
if chmod +x "$P$BIN"; then
echo "Added the executable bit to '$BIN'"
else
echo "Couldn't add the executable bit to '$BIN'"
fi
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | rabbit |
