Re: BASH in Cygwin and *nix

From: Larry I Smith (larryXiXsmith_at_verizon.net)
Date: 08/03/04


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 ----
>
> #!/bin/bash
>
> # Check project path
> if [ ! -d $PROJECT_PATH ]; then
> echo "Error :: PROJECT_PATH environment variable not set or not valid."
> exit 1
> fi
>
> ---- 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

Regards,
Larry

-- 
Anti-spam address, change each 'X' to '.' to reply directly.


Relevant Pages

  • Re: BASH in Cygwin and *nix
    ... > Hanna Lord wrote: ... >> I have just tried to run a BASH script that was written on a Slackware ... >> additional to Cygwin or my scripts to make them Cygwin happy? ...
    (comp.os.linux.development.apps)
  • Re: Scheduling Jobs - Last day of the month - HOWTO?
    ... Unfortunately, my environment is Cygwin, and the job to be ... I would request indepth consideration be ... As such, you have access to many languages, including C, but not VB ... You can probably even do this with a bash script. ...
    (comp.os.linux.misc)
  • BASH in Cygwin and *nix
    ... I have just tried to run a BASH script that was written on a Slackware 10 ... additional to Cygwin or my scripts to make them Cygwin happy? ...
    (comp.os.linux.development.apps)