Solved bash --version is invalid

Code:
# freebsd-version
12.3-RELEASE-p5

# pkg info bash
bash-5.1.16
Name           : bash
Version        : 5.1.16

# bash --version
bash: --: invalid option
Usage:    bash [GNU long option] [option] ...
    bash [GNU long option] [option] script-file ...
GNU long options:
    --debug
    --debugger
    --dump-po-strings
    --dump-strings
    --help
    --init-file
    --login
    --noediting
    --noprofile
    --norc
    --posix
    --pretty-print
    --rcfile
    --restricted
    --verbose
    --version
Shell options:
    -ilrsD or -c command or -O shopt_option        (invocation only)
    -abefhkmnptuvxBCHP or -o option

The default usage states that --version is a valid option. But, I cannot seem to get it to work. Am I missing something?
 
what's the output of "which bash"?
I have that version on a 13.1 system and --version works as it should.
My question should let us see if "bash" is aliased or something with maybe options incompatible with --version.
which bash should return /usr/local/bin/bash
 
I am still using FreeBSD-12.3p5 as well. The command works here. I am using packages with their default config, not the port infrastructure.
Code:
$ bash --version
GNU bash, Version 5.1.16(0)-release (amd64-portbld-freebsd12.2)
Copyright (C) 2020 Free Software Foundation, Inc.
Lizenz GPLv3+: GNU GPL Version 3 oder jünger <http://gnu.org/licenses/gpl.html>

Dies ist freie Software. Sie darf verändert und verteilt werden.
Es wird keine Garantie gewährt, soweit das Gesetz es zulässt.
 
Any chance you introduced nonprintable character into the command ? Try pasting bash --version 2>&1|hd | head -2.
 
The problem appears to be an alias alias bash='bash -l'. Running /usr/local/bin/bash --version works fine.
 
There's no way to alleviate that problem in an alias for all combinations of possible options.
This is the reason, bash(1):
Code:
OPTIONS
       All of the single-character shell options documented in the description
       of the set builtin command, including -o, can be used as options  when
       the  shell  is invoked. In addition, bash interprets the following op-
       tions when it is invoked:
[...]
       Bash  also  interprets  a number of multi-character options.  These op-
       tions must appear on the command line before the single-character  op-
       tions to be recognized.
[...]
       --version
          Show version information for this instance of bash on the stan-
          dard output and exit successfully.

If you want to maintain the defined alias and use -- options, then, instead of the complete path specification, use:
Code:
# \bash --posix
The first character ("\") defeats the matching of the command with the defined alias; that also means that in such cases you'll have to specify the -l option explicitly of course.
 
The problem appears to be an alias alias bash='bash -l'.
Actuallly, using a "different" option in the definition of the alias does solve the problem of using it with any options on the command line—while keeping its meaning. bash(1):
Code:
OPTIONS
[...]
       Bash  also  interprets  a number of multi-character options.  These op-
       tions must appear on the command line before the single-character  op-
       tions to be recognized.
[...]
      --login
	      Equivalent to -l.

So, change the definition of the alias (perhaps defined in ~/.cshrc or ~/.tcshrc) to:
Code:
alias bash='bash --login'
Activate the new alias definition; according to where your alias is defined (say ~/.cshrc), do:
Code:
# source ~/.cshrc
Logout and then login again instead also works.
 
Back
Top