I'm writing a script where I have a default directory for outputting data or the user can specify a directory. The problem is, I don't know how to do this eloquently. Here is what I have:
#!/bin/bash
OUTPUT="$1"
DEFAULT_DIR=/Default/Dir/For/Me
if [ -z "$OUTPUT" ]
then
OUTPUT=.${DEFAULT_DIR}
else
OUTPUT=""${OUTPUT_DIR}""${DEFAULT_DIR}""
fi
echo "$OUTPUT"
If I do this
./script /
I get//Default/Dir/For/Me
If I do this
./script /home
I get/home/Default/Dir/For/Me
If I do this
./script /home/
I get/home//Default/Dir/For/Me
Is there any way to make this pretty and handle the first scenario properly? Obviously, the first scenario won't work because the directory //
does not exist.