-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_script.sh
More file actions
executable file
·43 lines (37 loc) · 1.06 KB
/
add_script.sh
File metadata and controls
executable file
·43 lines (37 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env bash
#
# Time-stamp: <Wednesday 2025-01-22 21:40:10 Jess Moore>
#
# Make script executable and add to ${HOME}/bin
#
function usage() {
echo "Usage: $(basename "$0") 'file'"
echo ""
echo "Description: This script makes the target script with name"
echo " [file].sh executable and copies it to "
echo " ~/bin where it is accessible in the PATH."
echo ""
echo "Arguments:"
echo " file: Name of script (excluding .sh)."
echo ""
exit 1 # Exit with a non-zero status to indicate an error
}
if [[ $# -eq 0 || $* == *"help"* || $* == *"-h"* ]]; then
usage
fi
SCRIPT_FILE=${1}.sh
COMMAND=${1}
SCRIPT_DIR=$(pwd)
SCRIPT_PATH="${SCRIPT_DIR}/${SCRIPT_FILE}"
BIN_DIR="${HOME}/bin"
echo "Script file: ${SCRIPT_PATH}"
echo "Command to be created ${COMMAND}"
if [[ -f $SCRIPT_PATH ]]; then
chmod u+x "${SCRIPT_PATH}"
ln -s "${SCRIPT_PATH}" "${BIN_DIR}"/"${COMMAND}"
echo "Done: created ${COMMAND}"
ls -l "${HOME}"/bin/"${COMMAND}"
else
echo "Error: missing $SCRIPT_PATH.";
exit 1;
fi;