Re: OT: variables
Hi,
keep in mind that the quotation marks, wildcard characters, and
variables are interpreted by the shell parser, not by the program
you run. By quoting you control what the program will get to see
as its list of arguments.
Hans wrote:
> 1. apt-get --purge remove 4.3.1-0-*
Without quotation marks around "*", the shell parser will list
all file names which match the search pattern "4.3.1-0-*".
Assumed that the current directory contains these files
1234-5678.foo
4.3.1-0-foo
4.3.1-0-bar
another_file
one_more
the program apt-get will get to see these four arguments:
--purge
remove
4.3.1-0-foo
4.3.1-0-bar
> 2. aptitude purge '~n4.3.1-0-*'
With the hard quotation marks arount it, the shell parser will just
unpack the text and use it as a single argument. aptitude will see
two arguments:
purge
~n4.3.1-0-*
I assume aptitude shall use the second argument for an own search
operation, which differs from what the shell parser would do.
> 3. aptitude purge 'deborphan --guess-all'
Again the shell parser will just unpack the content of the quotes.
This time they shall not prevent interpretation of "*" but the
splitting into two words at the blank character.
aptitude will see two arguments
purge
deborphan --guess-all
Here i assume, that aptitude shall learn a command line which
it will execute on its own discretion.
https://www.debian-administration.org/article/134/Removing_unnecessary_packages_with_deborphan
Since no variable evaluations are in the string, one could as well
have wrapped it in "-quotes.
> At the moment I find no example for "foo",
Let's invent some:
x=foo
y=bar
echo "$x - $y"
lets echo see and print the single argument
foo - bar
That's because "-quotes do not prevent evaluation of shell variables
by the shell parser.
> I see no system behind it. Looks weired for me.
There are the general rules for the shell parser and the particular
expectations of the programs towards their arguments.
Quotation marks are needed as soon as the program shall be fed with
arguments which the shell parser would convert in an undesired way.
------------------------------------------------------------------
If you want to see the effect of a list of arguments, try this
contraption
for i in --purge remove 4.3.1-0-* ; do echo "$i" ; done
should in above example situation print
--purge
remove
4.3.1-0-foo
4.3.1-0-bar
whereas
for i in '4.3.1-0-*' ; do echo "$i" ; done
will always print
4.3.1-0-*
Have a nice day :)
Thomas
Reply to: