1

I've copied a script from the unifi documentation

#!/bin/sh

## define required variables
username=admin
password=admin
baseurl=https://localhost:8443

## include the API library
. unifi_sh_api

unifi_login
# unifi_authorize_guest <mac> <minutes> [up=kbps] [down=kbps] [bytes=MB]
unifi_authorize_guest $1 $2
unifi_logout

This is the script and this is the file structure:

foo@site:/home/foo# ls
unifi.sh  unifi_sh_api

This is what I get when I try to execute the file. What can cause this? The file is obviously in the right folder.

foo@site:/home/foo# sh unifi.sh
unifi.sh: 9: .: unifi_sh_api: not found
4
  • 2
    What if you use source instead of .? Commented Mar 13, 2014 at 9:08
  • 1
    Add current directory that is . in PATH and export it. Then the execution will work.. Commented Mar 13, 2014 at 9:18
  • 1
    @fedorqui I thought "source" was just an alias for dot ("."), so I don't understand why you would suggest exchanging them. Would you mind enlightening me if you have a minute please? Commented Mar 13, 2014 at 9:46
  • @MarkSetchell honestly I believe they are the same, but I saw this thread: stackoverflow.com/questions/670191/… and thought that in certain cases they could have different behaviour. I am pretty sure that it is not the answer, though. Commented Mar 13, 2014 at 11:07

1 Answer 1

1

You are invoking bash as /bin/sh which puts bash into sh-compatibility mode. The POSIX standard says that:

If file does not contain a slash, the shell shall use the search path specified by PATH to find the directory containing file.

Which means that the current directory will not be searched unless it is part of $PATH:

$ /bin/sh -c '. test.sh'
/bin/sh: 1: .: t.sh: not found

$ /bin/sh -c 'PATH=".:$PATH"; . test.sh'
$

bash, however, seems to search the current directory:

$ /bin/bash -c '. test.sh'
$
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.