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.
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 $@ ; }
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 $@ ; }'
I wrote
[[ $(type -t w3m) == "w3m" ]] && unalias w3m
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.
$wrongCodeForCheckingWhetherAliasExists && unalias w3m
w3m() { /usr/bin/w3m -no-cookie -o auto-image=TRUE $@ ; }
You need to unalias w3m first. That's the real answer here.
POSIX sh only defines "foo()".
"function foo()" is therefore purely a bash extension.
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
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.
Roger Price <debian@rogerprice.org> writes:
[[ $(type -t w3m) == "w3m" ]] && unalias w3m
Shouldn't that be
[[ $(type -t w3m) == "alias" ]] && unalias w3m
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.
* 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.
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!
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (2 / 14) |
Uptime: | 00:30:15 |
Calls: | 10,385 |
Calls today: | 2 |
Files: | 14,057 |
Messages: | 6,416,569 |