I'm trying to implement a help message on my shell script to get a usage example when running my script with "-h" as a parameter. I looked for ways to do it on-line but it's just not working...
This is my code:
#!/usr/bin/env sh
usage="$(basename "$0") [-h] -- program to change all files from one extension to another extension
where:
-h show this help text
ext1 extension to be changed
ext2 new desired extension
usage example: ./chage_entension.sh .cpp .c"
while [[ getopts ':hs:' option ]]; do
case "$option" in
h) echo "$usage"
;;
esac
done
shift $((OPTIND - 1))
ext1 = "$1"
ext2 = "$2"
for file in *$1; do
mv "$file" "`basename "$file" $1`$2"
done
And this are the errors I'm getting when trying to run ./change_extension.sh
/home/andre/src/scripts/change_extension.sh: line 12: conditional binary operator expected
/home/andre/src/scripts/change_extension.sh: line 12: syntax error near `':hs:''
/home/andre/src/scripts/change_extension.sh: line 12: `while [[ getopts ':hs:' option ]]; do'