• Re: readlink: invalid option -- 'b' and dirname: invalid option -- 'b'.

    From Lew Pitcher@21:1/5 to hongy...@gmail.com on Tue Apr 5 15:09:22 2022
    On Tue, 05 Apr 2022 07:37:07 -0700, hongy...@gmail.com wrote:

    Today, when I tried to connect to my computer using SSH, I noticed the following strange information after logging in:

    ```
    $ ssh werner@localhost
    [...]
    dirname: invalid option -- 'b'
    Try 'dirname --help' for more information.
    readlink: invalid option -- 'b'
    Try 'readlink --help' for more information.
    ```

    What do they mean, and what triggered them?

    What do they mean? Well, on the face of it, they mean that
    neither dirname(1) nor readlink(1) take a 'b' option.

    As for what triggered these error messages, your guess
    is as good as ours. Most likely, you have some poorly
    formed commands in the various shell scripts invoked
    when you establish an SSH connection and login.

    Look for dirname and readlink in those scripts, and ensure
    that the arguments passed to those commands properly
    resolve to syntatically correct commands. Specifically,
    be suspicious of any substitution variables, as they may
    not have the values you expect.

    HTH
    --
    Lew Pitcher
    "In Skills, We Trust"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hongyi.zhao@gmail.com@21:1/5 to All on Tue Apr 5 07:37:07 2022
    Today, when I tried to connect to my computer using SSH, I noticed the following strange information after logging in:

    ```
    $ ssh werner@localhost
    [...]
    dirname: invalid option -- 'b'
    Try 'dirname --help' for more information.
    readlink: invalid option -- 'b'
    Try 'readlink --help' for more information.
    ```

    What do they mean, and what triggered them?

    Regards,
    HZ

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hongyi.zhao@gmail.com@21:1/5 to Lew Pitcher on Tue Apr 5 18:01:18 2022
    On Tuesday, April 5, 2022 at 11:09:27 PM UTC+8, Lew Pitcher wrote:
    On Tue, 05 Apr 2022 07:37:07 -0700, hongy...@gmail.com wrote:

    Today, when I tried to connect to my computer using SSH, I noticed the following strange information after logging in:

    ```
    $ ssh werner@localhost
    [...]
    dirname: invalid option -- 'b'
    Try 'dirname --help' for more information.
    readlink: invalid option -- 'b'
    Try 'readlink --help' for more information.
    ```

    What do they mean, and what triggered them?
    What do they mean? Well, on the face of it, they mean that
    neither dirname(1) nor readlink(1) take a 'b' option.

    As for what triggered these error messages, your guess
    is as good as ours. Most likely, you have some poorly
    formed commands in the various shell scripts invoked
    when you establish an SSH connection and login.

    Look for dirname and readlink in those scripts, and ensure
    that the arguments passed to those commands properly
    resolve to syntatically correct commands. Specifically,
    be suspicious of any substitution variables, as they may
    not have the values you expect.

    The following is some code snippet in one of the various shell scripts invoked when I establish an SSH connection and login:

    ```
    unset scriptdir_realpath
    unset script_realdirname script_realname
    unset script_realbasename script_realextname
    unset script_realpath pkg_realpath

    scriptdir_realpath=$(cd -P -- "$(dirname -- "${1:-${BASH_SOURCE[0]}}")" && pwd -P)

    script_realdirname=$(dirname -- "$(realpath -e -- "${1:-${BASH_SOURCE[0]}}")") script_realname=$(basename -- "$(realpath -e -- "${1:-${BASH_SOURCE[0]}}")")

    script_realbasename=${script_realname%.*} script_realextname=${script_realname##*.}

    script_realpath=$script_realdirname/$script_realname pkg_realpath=${script_realpath%.*}

    unset script_dirname script_name
    unset script_basename script_extname
    unset script_path

    script_dirname=$(cd -- "$(dirname -- "${1:-${BASH_SOURCE[0]}}")" && pwd) script_name=$(basename -- "${1:-${BASH_SOURCE[0]}}")

    script_basename=${script_name%.*}
    script_extname=${script_name##*.}

    script_path=$script_dirname/$script_name
    ```

    Is my usage reasonable in the above code snippet?

    Regards,
    HZ

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lew Pitcher@21:1/5 to hongy...@gmail.com on Wed Apr 6 13:00:34 2022
    On Tue, 05 Apr 2022 18:01:18 -0700, hongy...@gmail.com wrote:

    On Tuesday, April 5, 2022 at 11:09:27 PM UTC+8, Lew Pitcher wrote:
    On Tue, 05 Apr 2022 07:37:07 -0700, hongy...@gmail.com wrote:

    Today, when I tried to connect to my computer using SSH, I noticed the following strange information after logging in:

    ```
    $ ssh werner@localhost
    [...]
    dirname: invalid option -- 'b'
    Try 'dirname --help' for more information.
    readlink: invalid option -- 'b'
    Try 'readlink --help' for more information.
    ```

    What do they mean, and what triggered them?
    What do they mean? Well, on the face of it, they mean that
    neither dirname(1) nor readlink(1) take a 'b' option.

    As for what triggered these error messages, your guess
    is as good as ours. Most likely, you have some poorly
    formed commands in the various shell scripts invoked
    when you establish an SSH connection and login.

    Look for dirname and readlink in those scripts, and ensure
    that the arguments passed to those commands properly
    resolve to syntatically correct commands. Specifically,
    be suspicious of any substitution variables, as they may
    not have the values you expect.

    The following is some code snippet in one of the various shell scripts invoked when I establish an SSH connection and login:

    ```
    [snip]
    scriptdir_realpath=$(cd -P -- "$(dirname -- "${1:-${BASH_SOURCE[0]}}")" && pwd -P)

    script_realdirname=$(dirname -- "$(realpath -e -- "${1:-${BASH_SOURCE[0]}}")")
    script_realname=$(basename -- "$(realpath -e -- "${1:-${BASH_SOURCE[0]}}")")
    [snip]
    script_dirname=$(cd -- "$(dirname -- "${1:-${BASH_SOURCE[0]}}")" && pwd) script_name=$(basename -- "${1:-${BASH_SOURCE[0]}}")
    [snip]
    Is my usage reasonable in the above code snippet?

    It depends.

    What is the snipped /supposed/ to do, and what does ${BASH_SOURCE[0]} expand to?


    --
    Lew Pitcher
    "In Skills, We Trust"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lew Pitcher@21:1/5 to Lew Pitcher on Wed Apr 6 13:01:31 2022
    On Wed, 06 Apr 2022 13:00:34 +0000, Lew Pitcher wrote:

    On Tue, 05 Apr 2022 18:01:18 -0700, hongy...@gmail.com wrote:

    On Tuesday, April 5, 2022 at 11:09:27 PM UTC+8, Lew Pitcher wrote:
    On Tue, 05 Apr 2022 07:37:07 -0700, hongy...@gmail.com wrote:

    Today, when I tried to connect to my computer using SSH, I noticed the following strange information after logging in:

    ```
    $ ssh werner@localhost
    [...]
    dirname: invalid option -- 'b'
    Try 'dirname --help' for more information.
    readlink: invalid option -- 'b'
    Try 'readlink --help' for more information.
    ```

    What do they mean, and what triggered them?
    What do they mean? Well, on the face of it, they mean that
    neither dirname(1) nor readlink(1) take a 'b' option.

    As for what triggered these error messages, your guess
    is as good as ours. Most likely, you have some poorly
    formed commands in the various shell scripts invoked
    when you establish an SSH connection and login.

    Look for dirname and readlink in those scripts, and ensure
    that the arguments passed to those commands properly
    resolve to syntatically correct commands. Specifically,
    be suspicious of any substitution variables, as they may
    not have the values you expect.

    The following is some code snippet in one of the various shell scripts invoked when I establish an SSH connection and login:

    ```
    [snip]
    scriptdir_realpath=$(cd -P -- "$(dirname -- "${1:-${BASH_SOURCE[0]}}")" && pwd -P)

    script_realdirname=$(dirname -- "$(realpath -e -- "${1:-${BASH_SOURCE[0]}}")")
    script_realname=$(basename -- "$(realpath -e -- "${1:-${BASH_SOURCE[0]}}")")
    [snip]
    script_dirname=$(cd -- "$(dirname -- "${1:-${BASH_SOURCE[0]}}")" && pwd)
    script_name=$(basename -- "${1:-${BASH_SOURCE[0]}}")
    [snip]
    Is my usage reasonable in the above code snippet?

    It depends.

    What is the snipped /supposed/ to do, and what does ${BASH_SOURCE[0]} expand to?
    And, what does $1 expand to?




    --
    Lew Pitcher
    "In Skills, We Trust"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hongyi.zhao@gmail.com@21:1/5 to Lew Pitcher on Wed Apr 6 06:17:40 2022
    On Wednesday, April 6, 2022 at 9:01:37 PM UTC+8, Lew Pitcher wrote:
    On Wed, 06 Apr 2022 13:00:34 +0000, Lew Pitcher wrote:

    On Tue, 05 Apr 2022 18:01:18 -0700, hongy...@gmail.com wrote:

    On Tuesday, April 5, 2022 at 11:09:27 PM UTC+8, Lew Pitcher wrote:
    On Tue, 05 Apr 2022 07:37:07 -0700, hongy...@gmail.com wrote:

    Today, when I tried to connect to my computer using SSH, I noticed the following strange information after logging in:

    ```
    $ ssh werner@localhost
    [...]
    dirname: invalid option -- 'b'
    Try 'dirname --help' for more information.
    readlink: invalid option -- 'b'
    Try 'readlink --help' for more information.
    ```

    What do they mean, and what triggered them?
    What do they mean? Well, on the face of it, they mean that
    neither dirname(1) nor readlink(1) take a 'b' option.

    As for what triggered these error messages, your guess
    is as good as ours. Most likely, you have some poorly
    formed commands in the various shell scripts invoked
    when you establish an SSH connection and login.

    Look for dirname and readlink in those scripts, and ensure
    that the arguments passed to those commands properly
    resolve to syntatically correct commands. Specifically,
    be suspicious of any substitution variables, as they may
    not have the values you expect.

    The following is some code snippet in one of the various shell scripts invoked when I establish an SSH connection and login:

    ```
    [snip]
    scriptdir_realpath=$(cd -P -- "$(dirname -- "${1:-${BASH_SOURCE[0]}}")" && pwd -P)

    script_realdirname=$(dirname -- "$(realpath -e -- "${1:-${BASH_SOURCE[0]}}")")
    script_realname=$(basename -- "$(realpath -e -- "${1:-${BASH_SOURCE[0]}}")")
    [snip]
    script_dirname=$(cd -- "$(dirname -- "${1:-${BASH_SOURCE[0]}}")" && pwd) >> script_name=$(basename -- "${1:-${BASH_SOURCE[0]}}")
    [snip]
    Is my usage reasonable in the above code snippet?

    It depends.

    What is the snipped /supposed/ to do, and what does ${BASH_SOURCE[0]} expand to?
    And, what does $1 expand to?

    I use it as a bash based library script, which, when sourced from another bash script with this script's name as the argument, i.e., $1, will give some path/script name related information of the invoking script. OTOH, if the script is sourced without
    any argument, the ${BASH_SOURCE[0]} will be used to gather path/script name related information of the library script itself.

    Regards,
    HZ


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lew Pitcher@21:1/5 to hongy...@gmail.com on Wed Apr 6 14:59:22 2022
    On Wed, 06 Apr 2022 06:17:40 -0700, hongy...@gmail.com wrote:

    On Wednesday, April 6, 2022 at 9:01:37 PM UTC+8, Lew Pitcher wrote:
    On Wed, 06 Apr 2022 13:00:34 +0000, Lew Pitcher wrote:

    On Tue, 05 Apr 2022 18:01:18 -0700, hongy...@gmail.com wrote:

    On Tuesday, April 5, 2022 at 11:09:27 PM UTC+8, Lew Pitcher wrote:
    On Tue, 05 Apr 2022 07:37:07 -0700, hongy...@gmail.com wrote:

    Today, when I tried to connect to my computer using SSH, I noticed the following strange information after logging in:

    ```
    $ ssh werner@localhost
    [...]
    dirname: invalid option -- 'b'
    Try 'dirname --help' for more information.
    readlink: invalid option -- 'b'
    Try 'readlink --help' for more information.
    ```

    What do they mean, and what triggered them?
    What do they mean? Well, on the face of it, they mean that
    neither dirname(1) nor readlink(1) take a 'b' option.

    As for what triggered these error messages, your guess
    is as good as ours. Most likely, you have some poorly
    formed commands in the various shell scripts invoked
    when you establish an SSH connection and login.

    Look for dirname and readlink in those scripts, and ensure
    that the arguments passed to those commands properly
    resolve to syntatically correct commands. Specifically,
    be suspicious of any substitution variables, as they may
    not have the values you expect.

    The following is some code snippet in one of the various shell scripts invoked when I establish an SSH connection and login:

    ```
    [snip]
    scriptdir_realpath=$(cd -P -- "$(dirname -- "${1:-${BASH_SOURCE[0]}}")" && pwd -P)

    script_realdirname=$(dirname -- "$(realpath -e -- "${1:-${BASH_SOURCE[0]}}")")
    script_realname=$(basename -- "$(realpath -e -- "${1:-${BASH_SOURCE[0]}}")")
    [snip]
    script_dirname=$(cd -- "$(dirname -- "${1:-${BASH_SOURCE[0]}}")" && pwd) >> >> script_name=$(basename -- "${1:-${BASH_SOURCE[0]}}")
    [snip]
    Is my usage reasonable in the above code snippet?

    It depends.

    What is the snipped /supposed/ to do, and what does ${BASH_SOURCE[0]} expand to?
    And, what does $1 expand to?

    I use it as a bash based library script, which, when sourced from another bash script with this script's name as the argument, i.e., $1, will give some path/script name related information of the invoking script. OTOH, if the script is sourced without
    any argument, the ${BASH_SOURCE[0]} will be used to gather path/script name related information of the library script itself.

    And now we know what the snippet is supposed to do.

    As for your failure mode, you still need to answer the questions
    (specifically, when you encounter the error messages),
    1) what does ${BASH_SOURCE[0]} expand to?
    2) what does $1 expand to

    --
    Lew Pitcher
    "In Skills, We Trust"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hongyi.zhao@gmail.com@21:1/5 to Lew Pitcher on Wed Apr 6 18:00:43 2022
    On Wednesday, April 6, 2022 at 10:59:27 PM UTC+8, Lew Pitcher wrote:
    On Wed, 06 Apr 2022 06:17:40 -0700, hongy...@gmail.com wrote:

    On Wednesday, April 6, 2022 at 9:01:37 PM UTC+8, Lew Pitcher wrote:
    On Wed, 06 Apr 2022 13:00:34 +0000, Lew Pitcher wrote:

    On Tue, 05 Apr 2022 18:01:18 -0700, hongy...@gmail.com wrote:

    On Tuesday, April 5, 2022 at 11:09:27 PM UTC+8, Lew Pitcher wrote:
    On Tue, 05 Apr 2022 07:37:07 -0700, hongy...@gmail.com wrote:

    Today, when I tried to connect to my computer using SSH, I noticed the following strange information after logging in:

    ```
    $ ssh werner@localhost
    [...]
    dirname: invalid option -- 'b'
    Try 'dirname --help' for more information.
    readlink: invalid option -- 'b'
    Try 'readlink --help' for more information.
    ```

    What do they mean, and what triggered them?
    What do they mean? Well, on the face of it, they mean that
    neither dirname(1) nor readlink(1) take a 'b' option.

    As for what triggered these error messages, your guess
    is as good as ours. Most likely, you have some poorly
    formed commands in the various shell scripts invoked
    when you establish an SSH connection and login.

    Look for dirname and readlink in those scripts, and ensure
    that the arguments passed to those commands properly
    resolve to syntatically correct commands. Specifically,
    be suspicious of any substitution variables, as they may
    not have the values you expect.

    The following is some code snippet in one of the various shell scripts invoked when I establish an SSH connection and login:

    ```
    [snip]
    scriptdir_realpath=$(cd -P -- "$(dirname -- "${1:-${BASH_SOURCE[0]}}")" && pwd -P)

    script_realdirname=$(dirname -- "$(realpath -e -- "${1:-${BASH_SOURCE[0]}}")")
    script_realname=$(basename -- "$(realpath -e -- "${1:-${BASH_SOURCE[0]}}")")
    [snip]
    script_dirname=$(cd -- "$(dirname -- "${1:-${BASH_SOURCE[0]}}")" && pwd)
    script_name=$(basename -- "${1:-${BASH_SOURCE[0]}}")
    [snip]
    Is my usage reasonable in the above code snippet?

    It depends.

    What is the snipped /supposed/ to do, and what does ${BASH_SOURCE[0]} expand to?
    And, what does $1 expand to?

    I use it as a bash based library script, which, when sourced from another bash script with this script's name as the argument, i.e., $1, will give some path/script name related information of the invoking script. OTOH, if the script is sourced
    without any argument, the ${BASH_SOURCE[0]} will be used to gather path/script name related information of the library script itself.
    And now we know what the snippet is supposed to do.

    As for your failure mode, you still need to answer the questions (specifically, when you encounter the error messages),
    1) what does ${BASH_SOURCE[0]} expand to?
    2) what does $1 expand to

    See the following:

    $ cat bash-lib.sh
    unset scriptdir_realpath
    unset script_realdirname script_realname
    unset script_realbasename script_realextname
    unset script_realpath pkg_realpath

    scriptdir_realpath=$(cd -P -- "$(dirname -- "${1:-${BASH_SOURCE[0]}}")" && pwd -P)

    script_realdirname=$(dirname -- "$(realpath -e -- "${1:-${BASH_SOURCE[0]}}")") script_realname=$(basename -- "$(realpath -e -- "${1:-${BASH_SOURCE[0]}}")")

    script_realbasename=${script_realname%.*} script_realextname=${script_realname##*.}

    script_realpath=$script_realdirname/$script_realname pkg_realpath=${script_realpath%.*}

    unset script_dirname script_name
    unset script_basename script_extname
    unset script_path

    script_dirname=$(cd -- "$(dirname -- "${1:-${BASH_SOURCE[0]}}")" && pwd) script_name=$(basename -- "${1:-${BASH_SOURCE[0]}}")

    script_basename=${script_name%.*}
    script_extname=${script_name##*.}

    script_path=$script_dirname/$script_name

    echo ''
    echo '${BASH_SOURCE[0]}=' ${BASH_SOURCE[0]}
    echo '$1=' $1

    $ cat test-bash-lib.sh
    . bash-lib.sh

    echo ''
    echo '${BASH_SOURCE[0]}=' ${BASH_SOURCE[0]}
    echo '$1=' $1

    $ . bash-lib.sh

    ${BASH_SOURCE[0]}= bash-lib.sh
    $1=

    $ . test-bash-lib.sh

    ${BASH_SOURCE[0]}= bash-lib.sh
    $1=

    ${BASH_SOURCE[0]}= test-bash-lib.sh
    $1=

    Regards,
    HZ

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lew Pitcher@21:1/5 to hongy...@gmail.com on Thu Apr 7 16:04:56 2022
    On Wed, 06 Apr 2022 18:00:43 -0700, hongy...@gmail.com wrote:

    On Wednesday, April 6, 2022 at 10:59:27 PM UTC+8, Lew Pitcher wrote:
    On Wed, 06 Apr 2022 06:17:40 -0700, hongy...@gmail.com wrote:

    On Wednesday, April 6, 2022 at 9:01:37 PM UTC+8, Lew Pitcher wrote:
    On Wed, 06 Apr 2022 13:00:34 +0000, Lew Pitcher wrote:

    On Tue, 05 Apr 2022 18:01:18 -0700, hongy...@gmail.com wrote:

    On Tuesday, April 5, 2022 at 11:09:27 PM UTC+8, Lew Pitcher wrote:
    On Tue, 05 Apr 2022 07:37:07 -0700, hongy...@gmail.com wrote:

    Today, when I tried to connect to my computer using SSH, I noticed the following strange information after logging in:

    ```
    $ ssh werner@localhost
    [...]
    dirname: invalid option -- 'b'
    Try 'dirname --help' for more information.
    readlink: invalid option -- 'b'
    Try 'readlink --help' for more information.
    ```

    What do they mean, and what triggered them?
    What do they mean? Well, on the face of it, they mean that
    neither dirname(1) nor readlink(1) take a 'b' option.

    As for what triggered these error messages, your guess
    is as good as ours. Most likely, you have some poorly
    formed commands in the various shell scripts invoked
    when you establish an SSH connection and login.

    Look for dirname and readlink in those scripts, and ensure
    that the arguments passed to those commands properly
    resolve to syntatically correct commands. Specifically,
    be suspicious of any substitution variables, as they may
    not have the values you expect.

    The following is some code snippet in one of the various shell scripts invoked when I establish an SSH connection and login:

    ```
    [snip]
    scriptdir_realpath=$(cd -P -- "$(dirname -- "${1:-${BASH_SOURCE[0]}}")" && pwd -P)

    script_realdirname=$(dirname -- "$(realpath -e -- "${1:-${BASH_SOURCE[0]}}")")
    script_realname=$(basename -- "$(realpath -e -- "${1:-${BASH_SOURCE[0]}}")")
    [snip]
    script_dirname=$(cd -- "$(dirname -- "${1:-${BASH_SOURCE[0]}}")" && pwd)
    script_name=$(basename -- "${1:-${BASH_SOURCE[0]}}")
    [snip]
    Is my usage reasonable in the above code snippet?

    It depends.

    What is the snipped /supposed/ to do, and what does ${BASH_SOURCE[0]} expand to?
    And, what does $1 expand to?

    I use it as a bash based library script, which, when sourced from another bash script with this script's name as the argument, i.e., $1, will give some path/script name related information of the invoking script. OTOH, if the script is sourced
    without any argument, the ${BASH_SOURCE[0]} will be used to gather path/script name related information of the library script itself.
    And now we know what the snippet is supposed to do.

    As for your failure mode, you still need to answer the questions
    (specifically, when you encounter the error messages),
    1) what does ${BASH_SOURCE[0]} expand to?
    2) what does $1 expand to

    See the following:

    $ cat bash-lib.sh
    [snip]

    That tells me nothing that I can't see from your previous snippet.

    So, let's recap.

    You have a script or scripts, buried somewhere within the sum total
    of scripts that ssh executes on your behalf when you log in to a
    remote system, that generate specific error messages. You wish to
    debug and rectify these error messages. The error messages are:
    dirname: invalid option -- 'b'
    Try 'dirname --help' for more information.
    readlink: invalid option -- 'b'
    Try 'readlink --help' for more information.

    First off, the error messages are mostly self-explanatory. Somewhere
    in your scripts, you invoke dirname(1) with the "-b" option, and
    elsewhere, you invoke readlink(1), again with the "-b" option. Neither dirname(1) nor readlink(1) /have/ a "-b" option, and tell you so.

    So, you have to determine
    1) where the offending dirname(1) is,
    2) how that dirname(1) gets an errant "-b" option,
    3) where the offending readlink(1) is, and
    4) how that readlink(1) gets an errant "-b" option

    Then, you have to change things so that neither the
    dirname(1) nor the readlink(1) get the bad "-b" option.

    By implication, you have isolated the offending dirname(1) and
    readlink(1) invocations to a specific code snippet, which you
    posted here. These invocations depend on the /specific values/
    of two parameters: $1 and ${BASH_SOURCE[0]}. The values of these
    two parameters, on login via ssh, will tell you if you have
    located the offending code snippet. At least one of these values
    will contain a "-b", the offending option passed to dirname(1)
    and readlink(1).

    Find that, and fix it.

    HTH
    --30--
    --
    Lew Pitcher
    "In Skills, We Trust"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Helmut Waitzmann@21:1/5 to All on Thu Apr 7 20:59:25 2022
    "hongy...@gmail.com" <hongyi.zhao@gmail.com>:
    On Tuesday, April 5, 2022 at 11:09:27 PM UTC+8, Lew Pitcher wrote:
    On Tue, 05 Apr 2022 07:37:07 -0700, hongy...@gmail.com wrote:

    Today, when I tried to connect to my computer using SSH, I
    noticed the following strange information after logging in:

    ```
    $ ssh werner@localhost
    [...]
    dirname: invalid option -- 'b'
    Try 'dirname --help' for more information.
    readlink: invalid option -- 'b'
    Try 'readlink --help' for more information.
    ```

    What do they mean, and what triggered them?

    What do they mean? Well, on the face of it, they mean that
    neither dirname(1) nor readlink(1) take a 'b' option.

    As for what triggered these error messages, your guess
    is as good as ours. Most likely, you have some poorly
    formed commands in the various shell scripts invoked
    when you establish an SSH connection and login.

    Look for dirname and readlink in those scripts, and ensure
    that the arguments passed to those commands properly
    resolve to syntatically correct commands. Specifically,
    be suspicious of any substitution variables, as they may
    not have the values you expect.

    The following is some code snippet in one of the various shell
    scripts invoked when I establish an SSH connection and login:


    […]

    In that code snippet, there is no invocation of "readlink".


    Also, in that code snippet, all invocations of "dirname" are of the
    form

    dirname -- further parameters

    Even, if a "-b" were part of the further parameters, it would not
    be interpreted by "dirname" as an option "b" because of the option
    terminator "--".

    That code snippet is not the cause of the error messages.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hongyi.zhao@gmail.com@21:1/5 to hongy...@gmail.com on Thu Apr 7 19:03:55 2022
    On Thursday, April 7, 2022 at 9:00:45 AM UTC+8, hongy...@gmail.com wrote:
    On Wednesday, April 6, 2022 at 10:59:27 PM UTC+8, Lew Pitcher wrote:
    On Wed, 06 Apr 2022 06:17:40 -0700, hongy...@gmail.com wrote:

    On Wednesday, April 6, 2022 at 9:01:37 PM UTC+8, Lew Pitcher wrote:
    On Wed, 06 Apr 2022 13:00:34 +0000, Lew Pitcher wrote:

    On Tue, 05 Apr 2022 18:01:18 -0700, hongy...@gmail.com wrote:

    On Tuesday, April 5, 2022 at 11:09:27 PM UTC+8, Lew Pitcher wrote: >> >>> On Tue, 05 Apr 2022 07:37:07 -0700, hongy...@gmail.com wrote:

    Today, when I tried to connect to my computer using SSH, I noticed the following strange information after logging in:

    ```
    $ ssh werner@localhost
    [...]
    dirname: invalid option -- 'b'
    Try 'dirname --help' for more information.
    readlink: invalid option -- 'b'
    Try 'readlink --help' for more information.
    ```

    What do they mean, and what triggered them?
    What do they mean? Well, on the face of it, they mean that
    neither dirname(1) nor readlink(1) take a 'b' option.

    As for what triggered these error messages, your guess
    is as good as ours. Most likely, you have some poorly
    formed commands in the various shell scripts invoked
    when you establish an SSH connection and login.

    Look for dirname and readlink in those scripts, and ensure
    that the arguments passed to those commands properly
    resolve to syntatically correct commands. Specifically,
    be suspicious of any substitution variables, as they may
    not have the values you expect.

    The following is some code snippet in one of the various shell scripts invoked when I establish an SSH connection and login:

    ```
    [snip]
    scriptdir_realpath=$(cd -P -- "$(dirname -- "${1:-${BASH_SOURCE[0]}}")" && pwd -P)

    script_realdirname=$(dirname -- "$(realpath -e -- "${1:-${BASH_SOURCE[0]}}")")
    script_realname=$(basename -- "$(realpath -e -- "${1:-${BASH_SOURCE[0]}}")")
    [snip]
    script_dirname=$(cd -- "$(dirname -- "${1:-${BASH_SOURCE[0]}}")" && pwd)
    script_name=$(basename -- "${1:-${BASH_SOURCE[0]}}")
    [snip]
    Is my usage reasonable in the above code snippet?

    It depends.

    What is the snipped /supposed/ to do, and what does ${BASH_SOURCE[0]} expand to?
    And, what does $1 expand to?

    I use it as a bash based library script, which, when sourced from another bash script with this script's name as the argument, i.e., $1, will give some path/script name related information of the invoking script. OTOH, if the script is sourced
    without any argument, the ${BASH_SOURCE[0]} will be used to gather path/script name related information of the library script itself.
    And now we know what the snippet is supposed to do.

    As for your failure mode, you still need to answer the questions (specifically, when you encounter the error messages),
    1) what does ${BASH_SOURCE[0]} expand to?
    2) what does $1 expand to
    See the following:

    $ cat bash-lib.sh
    unset scriptdir_realpath
    unset script_realdirname script_realname
    unset script_realbasename script_realextname
    unset script_realpath pkg_realpath
    scriptdir_realpath=$(cd -P -- "$(dirname -- "${1:-${BASH_SOURCE[0]}}")" && pwd -P)

    script_realdirname=$(dirname -- "$(realpath -e -- "${1:-${BASH_SOURCE[0]}}")")
    script_realname=$(basename -- "$(realpath -e -- "${1:-${BASH_SOURCE[0]}}")") script_realbasename=${script_realname%.*} script_realextname=${script_realname##*.}

    script_realpath=$script_realdirname/$script_realname pkg_realpath=${script_realpath%.*}

    unset script_dirname script_name
    unset script_basename script_extname
    unset script_path
    script_dirname=$(cd -- "$(dirname -- "${1:-${BASH_SOURCE[0]}}")" && pwd) script_name=$(basename -- "${1:-${BASH_SOURCE[0]}}") script_basename=${script_name%.*}
    script_extname=${script_name##*.}

    script_path=$script_dirname/$script_name
    echo ''
    echo '${BASH_SOURCE[0]}=' ${BASH_SOURCE[0]}
    echo '$1=' $1

    $ cat test-bash-lib.sh
    . bash-lib.sh

    echo ''
    echo '${BASH_SOURCE[0]}=' ${BASH_SOURCE[0]}
    echo '$1=' $1

    I should have written the following:

    $ cat test-bash-lib.sh
    . bash-lib.sh ${BASH_SOURCE[0]}

    echo ''
    echo '${BASH_SOURCE[0]}=' ${BASH_SOURCE[0]}
    echo '$1=' $1



    $ . bash-lib.sh

    ${BASH_SOURCE[0]}= bash-lib.sh
    $1=

    $ . test-bash-lib.sh

    ${BASH_SOURCE[0]}= bash-lib.sh
    $1=

    ${BASH_SOURCE[0]}= test-bash-lib.sh
    $1=

    And accordingly:

    $ . test-bash-lib.sh

    ${BASH_SOURCE[0]}= bash-lib.sh
    $1= test-bash-lib.sh

    ${BASH_SOURCE[0]}= test-bash-lib.sh
    $1=

    Regards,
    HZ

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)