Tilde shell extension does not work when passed as an option

I found that the tilde extension does not work for the following situation:

$ set -x

$ ./print_arg.pl destdir=~/test
+ ./print_arg.pl 'destdir=/root/test'
destdir=/root/test

$ ./print_arg.pl dest-dir=~/test
+ ./print_arg.pl 'dest-dir=~/test'
dest-dir=~/test

$ ./print_arg.pl -destdir=~/test
+ ./print_arg.pl '-destdir=~/test'
dest-dir=~/test

Content print_arg.pl

#!/usr/bin/perl
print $ARGV[0],"\n";

According to "Shell Processing Order," Shell will split the word to "tilde expansion." And I noticed that the split words are actually different. What is the reason for the different results?

+5
source share
1 answer

, destdir=~/test. dest-dir=~/test -destdir=~/test do not, - . destdir=~/test ( set -k), , - RHS.

http://www.gnu.org/software/bash/manual/html_node/Tilde-Expansion.html#Tilde-Expansion:

-, : . . , PATH, MAILPATH CDPATH, .

, -k , print_arg.pl:

~ $ set -kx
~ $ ./print_arg.pl destdir=~/bin foo
+ destdir=/Users/clint/bin
+ ./print_arg.pl foo
foo
~ $ ./print_arg.pl dest-dir=~/bin foo
+ ./print_arg.pl 'dest-dir=~/bin' foo
dest-dir=~/bin
+4

All Articles