RE: [Suggestion] Add warning/error when using the tilde expansion in a f
From:
Andrés Rodríguez Reina
Subject:
RE: [Suggestion] Add warning/error when using the tilde expansion in a folder where the tile-named file/folder exists
Date:
Wed, 12 Feb 2025 19:02:15 +0000
Thank you for taking the time to review this suggestion.
I agree that tilde expansion is not ambiguous, this suggestion is here just to
help clear the ambiguity in the user's mind/intent. And I also agree that any
other substitution is subject to cause the same confusion, but the case with
the tilde expansion produces more damage to inexperienced users. I mean: "rm
-rf *" just deletes the whole folder contents, while "rm -rf ~" deletes all
your files (similarly with other destructive commands).
For example: "rm -rf /" is also unambiguous, yet the command warns you about
the possible unintended consequences.
In any case, I'd say that in interactive mode and with a specific flag active,
I could find useful that no command with a $name/*/~/etc is executed when a
file by the same name is present at the current directory. Advanced users can
easily disable the flag and obtain full power/risk.
Best regards,
Andrés
-----Original Message-----
From: Lawrence Velázquez <vq@larryv.me>
Sent: 12 February 2025 19:46
To: Andrés Rodríguez Reina <areina@gmv.com>
Cc: Marina López Seoane <marina.lopez.seoane@gmv.com>; bug-bash@gnu.org
Subject: Re: [Suggestion] Add warning/error when using the tilde expansion in a
folder where the tile-named file/folder exists
On Wed, Feb 12, 2025, at 10:50 AM, Andrés Rodríguez Reina wrote:
> In my opinion, it would be useful to have a warning be issued
> when in interactive mode, when at the current working directory a
> file/folder named '~' exists, and a command with a parameter starting
> with ~ is used (which will produce tilde expansion).
You could say this about any unexpanded word.
touch '$var'
echo $var
touch '*'
ls *
set -H
touch '!$'
stat !$
Should the shell look for a directory entry for every word before it does
anything?
> Fix:
> When in interactive mode and when a suitable flag is
> activated, an error should appear. For example:
> <Error: use of ~ is ambiguous. Please either specify '~' or
> type the home path to avoid ambiguity.>
Tilde expansion may surprise inexperienced users, but there's nothing
"ambiguous" about it. It is well defined.
--
vq
P Please consider the environment before printing this e-mail.