Re: BASH in Cygwin and *nix
From: Larry I Smith (larryXiXsmith_at_verizon.net)
Date: Tue, 03 Aug 2004 17:14:15 GMT
Hanna Lord wrote:
> Hi all,
> I have just tried to run a BASH script that was written on a Slackware 10
> box on Cygwin (just installed) and I get errors, do I need to do something
> additional to Cygwin or my scripts to make them Cygwin happy?
> ---- START OF SCRIPT ----
> # Check project path
> if [ ! -d $PROJECT_PATH ]; then
> echo "Error :: PROJECT_PATH environment variable not set or not valid."
> exit 1
> ---- END OF SCRIPT ----
> If you run this under Slackware its happy, but under Cygwin I get the
> following error:
> proj_shell: line3: [: /test_stuff: binary operator expected
> Many thanks
You must first check for an empty/undefined PROJECT_PATH
before checking for its existence on disk.
"[ ! -d $PROJECT_PATH ]" produces undefined behaviour if
PROJECT_PATH is empty (i.e. your results may vary between
sh/bash implementations). This should work everywhere:
if [ -z $PROJECT_PATH ] || [ ! -d $PROJECT_PATH ]; then
-- Anti-spam address, change each 'X' to '.' to reply directly.