[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] confusion of shell's new option compat41
From: |
MaShimiao |
Subject: |
Re: [Help-bash] confusion of shell's new option compat41 |
Date: |
Thu, 17 Jan 2013 10:21:56 +0800 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 |
On 01/17/2013 03:42 AM, Chet Ramey wrote:
On 1/16/13 1:06 PM, Ma Shimiao wrote:
According to changelog and manpage, I find compat as a new option is added.
I have read manpage for many times. But I actually can't find out what it
affects.
And I don't understand what special character means.
ManPage as follow:
compat41
If set, bash, when in posix mode, treats a single quote in a dou‐
ble-quoted parameter expansion as a special character. The sin‐
gle quotes must match (an even number) and the characters between
the single quotes are considered quoted. This is the behavior of
posix mode through version 4.1. The default bash behavior
remains as in previous versions.
Could someone give me a example shows how to use compat41?
Look at what a bash-4.2 instance running in Posix mode does with this:
echo "${HOME+'foo}"
with and without compat41 enabled.
I test in Fedora16 and bash-4.2.28. there is nothing difference.
First, I wrote a script :
#!/bin/bash
shopt -s compat41
echo "${HOME+'foo}"
then, run it:
# bash --posix compat.sh
'foo
Second, I changed the script:
#!/bin/bash
shopt -u compat41
echo "${HOME+'foo}"
then, run it:
# bash --posix compat.sh
'foo
The compat41 option changes how this construct is expanded. With it
enabled, the single quote is special: it is a quote character, must have
an open and close quote, and results in the characters between the single
quotes being sort-of quoted.
I changed bash-4.2 posix mode to conform to a post-bash-4.1 Posix
interpretation. That interpretation put the burden of matching quotes on
the application, changed single quotes to be ordinary characters in a
double-quoted word expansion, and removed the requirement that the shell
ensure they match.
The default bash behavior doesn't change: it requires that the single
quotes match.
Chet