How can I “peek over” the bash command line argument extension?

I want the Perl script to accept wildcards (foo - *. Ba?) For file names (which are then processed for the entire directory subtree).

Of course, I can tell users of my script to quote the argument ('foo - *. Ba?'), But it's not very elegant - the wildcard method is meant as a user-friendly alternative to passing regular expressions (which are also accepted, and which, of course, should to be specified). The problem is that the shell (bash, in my case) extends the command line to files matching the lookup pattern in the current directory, so my poor script gets @ARGV preset with any found bash (usually nothing, or a bunch of foo-lotsof.baz and etc.).

Is there a bash copy of an unexpanded command line somewhere?

+3
source share
5 answers

Please do not try to get around this. Changing how the arguments are interpreted is done by the user when they select the citation. Even if you can (and I know that there are hooks in bash that I don’t know anything about, maybe you will), you won’t be able to provide a more convenient user experience in this way, you will be worse.

+4
source

According to the bash man page, you can disable the * ,? and [with the -f switch. See Extending the path name.

$ bash -f -c 'ls *'
ls: *: No such file or directory

But then you should ask your users to change the way bash starts, or you need to try to gain control over this. It just offsets the problem.

, .

EDIT: , ​​ unix . script.

+4

, . bash . find -name '*.txt', bash,

+3

, , , : (globbing), .

.

+3

Bash , . bash, bash, , . (, Windows , , Perl , .)

Quoting file names is a standard solution, and Linux command-line users should be familiar with it.

Other programs (such as find (1) ) have the same problem when you need to specify arguments that take wildcards.

(Even if you could somehow query the bash command line history from your Perl script to find the command when the user typed it, you will still have problems running your script, other shells, other scripts, etc.)

+2
source

Source: https://habr.com/ru/post/1757693/


All Articles