When I put an option in the middle, the case doesn't work. After, the script continues to work.
while getopts "t:target:" opt; do
case opt in
t)
test = "$OPTARG"
;;
target)
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
echo $TEST
if [[ "$2" != "-t" && "$2" != "-target" ]]; then
echo "The -t or -target option must be the second argument."
exit 1
fi
When i am doing :
./myScript file_path -t
I am getting :
realpath: '': No such file or directory
Directory not found at the second given path :
But normally it would work :) - case option
option requires an argument -- o
Please, help)