2

I am supporting two groups. I have one script, and I would like to keep it at one. I am having trouble with a test function:

convtype=./Sample*/
if [[ -n convtype ]]; then

where it runs fine for some users but not others. The one thing I've noticed is that for people running it from a PC either a value or Null string is returned depending on what is in the directory, so then my if statement will evaluate to true or false. For MAC users, it always evaluates to a string and therefore is always true.

if I change these two lines to:

 if [[ -d Sample*/ ]]; then

if works for the MAC users, but not the PC users.

I'm looking for either a way to tell which type of machine the script is being run from or a different way to generate/test the variable that will work regardless. Suggestions most appreciated.

  • Does the behavior change if you explicitly set #!/bin/bash followed by set -o posix in the first couple lines of the script? – Aaron Feb 20 '16 at 1:43
  • Is this the win10 bash or something else? – Jim B Oct 6 '16 at 23:33
-1

If the goal is to test if a directory exists and both systems are running in bash then you can do this working solution found in this working example

if ls /path/to/your/files* 1> /dev/null 2>&1; then
    echo "files do exist"
else
    echo "files do not exist"
fi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.