• Can a Bash function be named "w3m" ?

    From Roger Price@21:1/5 to All on Thu Jan 30 14:10:01 2025
    This message is in MIME format. The first part should be readable text,
    while the remaining parts are likely unreadable without MIME-aware tools.

    On a Debian 12 machine with bash 5.2.15-2+b7, I had this alias in my .bashrc

    alias w3m='/usr/bin/w3m -no-cookie -o auto-image=TRUE '

    I understand that aliases are frowned on and should be written as functions, so I wrote

    [[ $(type -t w3m) == "w3m" ]] && unalias w3m
    w3m() { /usr/bin/w3m -no-cookie -o auto-image=TRUE $@ ; }

    and received the error message

    bash: .bashrc: line 86: syntax error near unexpected token `('
    bash: .bashrc: line 86: `w3m() { /usr/bin/w3m -no-cookie -o auto-image=TRUE $@ ; }'

    To fix this, I remove the numeral 3 from w3m, write wm() ... and then the error disappears. But the bash man page says that numerals are allowed in names although it doesn´t say if a name can be a function name:

    name A word consisting only of alphanumeric characters and underscores, and
    beginning with an alphabetic character or an under‐score.

    The man page also says that a function name is an fname (not a name), and says "a function name can be any unquoted shell word that does not contain $".

    Nothing in the man page appears to reject w3m so I do not understand why my function name w3m is refused.

    Roger

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From tomas@tuxteam.de@21:1/5 to Greg Wooledge on Thu Jan 30 14:20:01 2025
    On Thu, Jan 30, 2025 at 08:13:15AM -0500, Greg Wooledge wrote:
    On Thu, Jan 30, 2025 at 13:59:37 +0100, Roger Price wrote:
    alias w3m='/usr/bin/w3m -no-cookie -o auto-image=TRUE '

    w3m() { /usr/bin/w3m -no-cookie -o auto-image=TRUE $@ ; }

    and received the error message

    bash: .bashrc: line 86: syntax error near unexpected token `('
    bash: .bashrc: line 86: `w3m() { /usr/bin/w3m -no-cookie -o auto-image=TRUE $@ ; }'

    The problem is you *already* have the alias, and the alias gets expanded
    when you try to define the function.

    D'oh. This actually only happens with aliases, you are right.
    In my other answer I posted some nonsense.

    Remember: in things shell (at least), if Greg says something and
    me something else, Greg is most probably right :-)

    Cheers
    --
    t

    -----BEGIN PGP SIGNATURE-----

    iF0EABECAB0WIQRp53liolZD6iXhAoIFyCz1etHaRgUCZ5t7+AAKCRAFyCz1etHa RpazAJwOvf+ixPsvS6PlsdmsKUIwlRYlNwCffpuI7xYGG8uFaoUEacN9KzSJMA4=
    =yf9k
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From tomas@tuxteam.de@21:1/5 to Roger Price on Thu Jan 30 14:20:01 2025
    On Thu, Jan 30, 2025 at 01:59:37PM +0100, Roger Price wrote:
    On a Debian 12 machine with bash 5.2.15-2+b7, I had this alias in my .bashrc

    alias w3m='/usr/bin/w3m -no-cookie -o auto-image=TRUE '

    I understand that aliases are frowned on and should be written as functions, so
    I wrote

    Wait a minute...

    [[ $(type -t w3m) == "w3m" ]] && unalias w3m
    w3m() { /usr/bin/w3m -no-cookie -o auto-image=TRUE $@ ; }

    ...the problem is that the command w3m exists: the shell
    expands that thing and tries to run it -- the parentheses
    then are a syntax error.

    Thing is, the line as you wrote it is ambiguous whenever the shell
    knows how to "run" w3m: shall it run it, or are you trying to define
    a function?

    The shell decides for the first.

    Try prefixing the thing with the builtin `function':

    function w3m() ...

    Cheers
    --
    t

    -----BEGIN PGP SIGNATURE-----

    iF0EABECAB0WIQRp53liolZD6iXhAoIFyCz1etHaRgUCZ5t6QgAKCRAFyCz1etHa Ri8iAJ9oL7htBoJhvpDeXVMG2nxaRHv+4wCfdc8cjlecP5ZsrX532z/pYMaVb0s=
    =SCBM
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Greg Wooledge@21:1/5 to Roger Price on Thu Jan 30 14:20:01 2025
    On Thu, Jan 30, 2025 at 13:59:37 +0100, Roger Price wrote:
    alias w3m='/usr/bin/w3m -no-cookie -o auto-image=TRUE '

    w3m() { /usr/bin/w3m -no-cookie -o auto-image=TRUE $@ ; }

    and received the error message

    bash: .bashrc: line 86: syntax error near unexpected token `('
    bash: .bashrc: line 86: `w3m() { /usr/bin/w3m -no-cookie -o auto-image=TRUE $@ ; }'

    The problem is you *already* have the alias, and the alias gets expanded
    when you try to define the function.

    hobbit:~$ alias grok=true
    hobbit:~$ grok() { echo hi; }
    hobbit:~$ grok
    hi
    hobbit:~$ true
    hi

    Aliases are insidious like that.

    I wrote

    [[ $(type -t w3m) == "w3m" ]] && unalias w3m

    Well, that doesn't work. I'm not sure what you were going for there,
    but that's not what "type -t" says for an alias.

    hobbit:~$ type ll
    ll is aliased to `ls -l'
    hobbit:~$ type -t ll
    alias

    To answer the question in the Subject header: yes, a function may be
    named w3m (without the quotes). Bash allows a stupidly large range
    of characters to be used in function names, including forward slashes.

    hobbit:~$ /bin/rm() { echo haha; }
    hobbit:~$ ls -l badfile
    ls: cannot access 'badfile': No such file or directory
    hobbit:~$ touch badfile
    hobbit:~$ /bin/rm badfile
    haha

    It's just your alias that was in the way.

    Even if you were writing for a pure POSIX sh (not that any such thing
    exists in reality), w3m would be a legal function name, because it's
    a legal variable name. All legal variable names are also legal function
    names under POSIX rules.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From tomas@tuxteam.de@21:1/5 to Greg Wooledge on Thu Jan 30 14:30:01 2025
    On Thu, Jan 30, 2025 at 08:18:26AM -0500, Greg Wooledge wrote:
    On Thu, Jan 30, 2025 at 14:10:33 +0100, tomas@tuxteam.de wrote:
    Try prefixing the thing with the builtin `function':

    function w3m() ...

    That would still leave the alias in place, though. So, both the alias
    and the function would be defined. The alias will win out, I believe,
    if you actually try to run w3m at that point.

    You need to unalias w3m first. That's the real answer here.

    [...]

    Yes, indeed. Also, see my other answer to your other post :-)

    Cheers
    --
    t

    -----BEGIN PGP SIGNATURE-----

    iF0EABECAB0WIQRp53liolZD6iXhAoIFyCz1etHaRgUCZ5t9WQAKCRAFyCz1etHa RrqjAJ90r6rDozghyvUM4fYTcmuqh7855gCfcbWy8ziJ7ZFVgDlgQMsUt0p6EhU=
    =rKVv
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Will Mengarini@21:1/5 to All on Thu Jan 30 15:00:01 2025
    * Roger Price <debian@rogerprice.org> [25-01/30=Th 13:59 +0100]:
    $wrongCodeForCheckingWhetherAliasExists && unalias w3m

    When I want to unalias something that might already be unaliased (as
    when it's in .bashrc), I just code
    unalias foo 2>/dev/null
    because file descriptor 2 is the standard error output.

    w3m() { /usr/bin/w3m -no-cookie -o auto-image=TRUE $@ ; }

    Speaking of w3m, was anybody part of its dev team long enough
    ago to know what happened to it? When I tried to join its
    mailing list linked from <https://w3m.sourceforge.net/> I got
    no response, even though I tried twice, a few months apart.

    w3m needs some serious maintenance. It's still my favorite browser, but
    I hear Google is planning to start requiring Javascript for searches,
    so somebody's going to have to step up if w3m is to remain viable.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Roger Price@21:1/5 to Greg Wooledge on Thu Jan 30 14:40:01 2025
    On Thu, 30 Jan 2025, Greg Wooledge wrote:

    You need to unalias w3m first. That's the real answer here.

    I wrote

    [[ $(type -t w3m) == "w3m" ]] && unalias w3m
    w3m() { /usr/bin/w3m -no-cookie -o auto-image=TRUE $@ ; }

    which I understood is sufficient to unalias the name w3m before defining the function.

    POSIX sh only defines "foo()".
    "function foo()" is therefore purely a bash extension.

    I stick to the basic definition of Bash functions. Roger

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Loris Bennett@21:1/5 to Roger Price on Thu Jan 30 14:50:01 2025
    Roger Price <debian@rogerprice.org> writes:

    On a Debian 12 machine with bash 5.2.15-2+b7, I had this alias in my .bashrc

    alias w3m='/usr/bin/w3m -no-cookie -o auto-image=TRUE '

    I understand that aliases are frowned on and should be written as functions, so
    I wrote

    [[ $(type -t w3m) == "w3m" ]] && unalias w3m

    Shouldn't that be

    [[ $(type -t w3m) == "alias" ]] && unalias w3m

    ?

    w3m() { /usr/bin/w3m -no-cookie -o auto-image=TRUE $@ ; }

    and received the error message

    bash: .bashrc: line 86: syntax error near unexpected token `('
    bash: .bashrc: line 86: `w3m() { /usr/bin/w3m -no-cookie -o auto-image=TRUE $@ ; }'

    To fix this, I remove the numeral 3 from w3m, write wm() ... and then the error
    disappears. But the bash man page says that numerals are allowed in names although it doesn´t say if a name can be a function name:

    name A word consisting only of alphanumeric characters and underscores, and
    beginning with an alphabetic character or an under‐score.

    The man page also says that a function name is an fname (not a name), and says
    "a function name can be any unquoted shell word that does not contain $".

    Nothing in the man page appears to reject w3m so I do not understand why my function name w3m is refused.

    Roger

    --
    This signature is currently under constuction.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Wanderer@21:1/5 to Will Mengarini on Thu Jan 30 15:20:02 2025
    This is an OpenPGP/MIME signed message (RFC 4880 and 3156)
    On 2025-01-30 at 08:52, Will Mengarini wrote:

    w3m needs some serious maintenance. It's still my favorite browser,
    but I hear Google is planning to start requiring Javascript for
    searches, so somebody's going to have to step up if w3m is to remain
    viable.

    Planning to? They already have - except that they have a whitelist of
    browsers they recognize as not supporting JS at all, and they serve
    search results (with different formatting) to those browsers anyway.
    They could of course be planning to drop that whitelist too, but so far
    I at least haven't heard any reports about that.

    If you spoof your User-Agent string to google.com as being for e.g.
    lynx, you can get those no-JS search-results pages even in Firefox. It's
    just only arguably worth it.

    On one of my computers, I've jumped through the needed hoops to set
    things up (with a browser extension) to spoof the UA for google.com and
    nowhere else. On another, I've switched search-engine defaults from
    Google to (the HTML-only version of) DuckDuckGo. So far neither is
    giving me such an obviously superior experience for me to decide to
    switch the other machine over so they both match.

    --
    The Wanderer

    The reasonable man adapts himself to the world; the unreasonable one
    persists in trying to adapt the world to himself. Therefore all
    progress depends on the unreasonable man. -- George Bernard Shaw


    -----BEGIN PGP SIGNATURE-----

    iQIzBAEBCgAdFiEEJCOqsZEc2qVC44pUBKk1jTQoMmsFAmebiX8ACgkQBKk1jTQo MmsoRhAAgdHCGWaF9fF2OP2zV8lMXyJHEmFEmjOgK+XXl8wEzhkP6qTYFxZ38q3t lTv/Rg1iGKkp7MpC73nqC8/0BrmxwIXSewZ4RvahNRJNulQ3Aa1566/2C3KENQcO OGHvF0itBOM8F2fLp+6+e5NLevG7z0SRNxEueakCIVaVsx6ZtOzlitYZ/kgE0ehH UDxJiqwOybrOQIwsd2wqrlmEDo/7I92MBqpoLjx0Q16vGIzBN1EEQ0+/lSxPLbar sFmDOOIma1oD6DD2HBdWDXiHnGQLAvF25tgERDGbSg4xFBdiW1zd+IYSgE2hNZGr KbIoJnqaUsotVDQZlWu53hoyOotyxTB5RwZ25UbEnbWNpxGoURXmbhAdIR/9Zuo5 BmasnshsMmJbQ37jI5getwvfgEI5lynwqo61WD/DsiRpCl1xvrhYOoHr3HurNGeF Cd239gZjEAqb8t+FaL502IrzDmTsrSHY25LPwhSElbQw2FApIHyGW5i7qF/63AjX tbc3jLZ9CIwgbYkEQanDac1G57fGUqTdsjZkvVeEMZBGen/hKku/d1our+dyioQh gs9nphngmMXD0EVn+yVVrsB4iO8uuSt7wz27KyDXmveeFDk+JzFG4OKFalxmKOXK TG4VXlE3VySI7/UxMzX7cBbqsRuR
  • From Roger Price@21:1/5 to Loris Bennett on Thu Jan 30 15:40:02 2025
    On Thu, 30 Jan 2025, Loris Bennett wrote:

    Roger Price <debian@rogerprice.org> writes:
    [[ $(type -t w3m) == "w3m" ]] && unalias w3m

    Shouldn't that be

    [[ $(type -t w3m) == "alias" ]] && unalias w3m

    You are right! From the Bash man page:

    type [-aftpP] name [name ...]
    With no options, indicate how each name would be interpreted
    if used as a command name. If the -t option is used, type
    prints a string which is one of alias, keyword, function, builtin,
    or file if name is an alias, shell reserved word, function,
    builtin, or disk file, respectively.

    I made the change and function w3m now works correctly. Thanks.

    Roger

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Owlett@21:1/5 to The Wanderer on Thu Jan 30 16:20:02 2025
    On 1/30/25 8:15 AM, The Wanderer wrote:
    On 2025-01-30 at 08:52, Will Mengarini wrote:

    w3m needs some serious maintenance. It's still my favorite browser,
    but I hear Google is planning to start requiring Javascript for
    searches, so somebody's going to have to step up if w3m is to remain
    viable.

    Planning to? They already have - except that they have a whitelist of browsers they recognize as not supporting JS at all, and they serve
    search results (with different formatting) to those browsers anyway.
    They could of course be planning to drop that whitelist too, but so far
    I at least haven't heard any reports about that.

    If you spoof your User-Agent string to google.com as being for e.g.
    lynx, you can get those no-JS search-results pages even in Firefox. It's
    just only arguably worth it.

    On one of my computers, I've jumped through the needed hoops to set
    things up (with a browser extension) to spoof the UA for google.com and nowhere else. On another, I've switched search-engine defaults from
    Google to (the HTML-only version of) DuckDuckGo. So far neither is
    giving me such an obviously superior experience for me to decide to
    switch the other machine over so they both match.


    I long ago set my default search engine to duckduckgo.com .
    No regrets!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David Wright@21:1/5 to Will Mengarini on Thu Jan 30 20:50:01 2025
    On Thu 30 Jan 2025 at 05:52:02 (-0800), Will Mengarini wrote:
    * Roger Price <debian@rogerprice.org> [25-01/30=Th 13:59 +0100]:
    $wrongCodeForCheckingWhetherAliasExists && unalias w3m

    When I want to unalias something that might already be unaliased (as
    when it's in .bashrc), I just code
    unalias foo 2>/dev/null
    because file descriptor 2 is the standard error output.

    Add || true to avoid a non-zero exit status.

    Cheers,
    David.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Roy J. Tellason, Sr.@21:1/5 to All on Thu Jan 30 23:00:01 2025
    On Thursday 30 January 2025 10:13:39 am Richard Owlett wrote:
    On another, I've switched search-engine defaults from
    Google to (the HTML-only version of) DuckDuckGo. So far neither is
    giving me such an obviously superior experience for me to decide to
    switch the other machine over so they both match.

    I long ago set my default search engine to duckduckgo.com .
    No regrets!

    Same here...

    --
    Member of the toughest, meanest, deadliest, most unrelenting -- and
    ablest -- form of life in this section of space,  a critter that can
    be killed but can't be tamed.  --Robert A. Heinlein, "The Puppet Masters"
    -
    Information is more dangerous than cannon to a society ruled by lies. --James M Dakin

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