Hi everyone,
My name is Liviu and I'm new on this forum although I've been using OpenSUSE for more than one year. I'm currently trying to learn scripting in BASH and encountered following issue: the condition testing doesn't always seems to work properly.
Following example is part of a script I'm writing for a quick file transfer to Dropbox:
if test -z "$1"; #checking if first parameter was entered (executes fine)
then
echo "Option not entered. Enter s for the Shared directory or p for the Private directory";
exit 1;
fi
if test "$1"!="s" && "$1"!="p"; #first parameter must either be s or p otherwise the script will exit with code 1
then
echo "Invalid option entered. Enter s for Shared, p for Private";
exit 1;
else
dir="$1";
src=`pwd`;
dest='/home/Liviu/Dropbox';
fi
When debugging with bashdb I got following issues:
- a "command not found" warning for the 6th line: if test "$1"!="s" && "$1"!="p"
- the "else" section seems executes even if the first script parameter is different than s or p
First section which checks if the first parameter was entered (-z) executes properly.
Am I doing something wrong? I tried to figure out if there are any syntax errors but I couldn't find any. And when using [ ] instead of test I also get weird script behavior.
Thanks in advance for your help!
Liviu
PS. Is there any way to debug scripts using EMACS? I'm using this tool for script writing and generally for text document processing.
My name is Liviu and I'm new on this forum although I've been using OpenSUSE for more than one year. I'm currently trying to learn scripting in BASH and encountered following issue: the condition testing doesn't always seems to work properly.
Following example is part of a script I'm writing for a quick file transfer to Dropbox:
if test -z "$1"; #checking if first parameter was entered (executes fine)
then
echo "Option not entered. Enter s for the Shared directory or p for the Private directory";
exit 1;
fi
if test "$1"!="s" && "$1"!="p"; #first parameter must either be s or p otherwise the script will exit with code 1
then
echo "Invalid option entered. Enter s for Shared, p for Private";
exit 1;
else
dir="$1";
src=`pwd`;
dest='/home/Liviu/Dropbox';
fi
When debugging with bashdb I got following issues:
- a "command not found" warning for the 6th line: if test "$1"!="s" && "$1"!="p"
- the "else" section seems executes even if the first script parameter is different than s or p
First section which checks if the first parameter was entered (-z) executes properly.
Am I doing something wrong? I tried to figure out if there are any syntax errors but I couldn't find any. And when using [ ] instead of test I also get weird script behavior.
Thanks in advance for your help!
Liviu
PS. Is there any way to debug scripts using EMACS? I'm using this tool for script writing and generally for text document processing.