Re: tilde character not interpreted in variable set

2018-03-02 Thread Nick Chambers


On 3/2/18, 9:03 AM, "bug-bash on behalf of Koncz, Istvan (Extern)" 
 wrote:


Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-unknown-linux-gnu'
-DCONF_VENDOR='unknown'
-DLOCALEDIR='/home/konczi.ext/apps/bin/share/locale' -DPACKAGE='bash'
-DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib   -g -O2 -Wno-
parentheses -Wno-format-security
uname output: Linux OED-EX-DIG-L 4.13.0-36-generic #40-Ubuntu SMP Fri
Feb 16 20:07:48 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-unknown-linux-gnu

Bash Version: 4.4
Patch Level: 18
Release Status: release

Description:
when i use ~/ for home folder it works in command line e.g. ls
-la ~/.vimrc works, but when i add it to a variable e.g. foo="~/.vimrc"
then ~/ will not be replaced to $HOME value like in command line, but i
think it should be. ~ is a special character so must be escapped like
\~ if i want the char, but without escape it should provide the home
like in ls -la ~/ command. In my oppinion it is a bug.
Current workaround is in shell script to use $HOME not ~/ but would be
better if ~/ would be consistent and behave everywhere as same.

Are you sure this is a bug? Consider the following:

ubuntu:~ nchambers$ echo ~
/home/nchambers
ubuntu:~ nchambers$ echo "~"
~
ubuntu:~ nchambers$ tmp=~
ubuntu:~ nchambers$ echo "$tmp"
/home/nchambers
ubuntu:~ nchambers$ tmp="~"
ubuntu:~ nchambers$ echo "$tmp"
~
ubuntu:~ nchambers$

~ is not an actual path, but rather a symbolic value expanded by the shell to 
whatever value is in HOME. Wrapping it in quotes prevents this expansion.

Repeat-By:
foo="~/.vimrc"
echo $foo
~/.vimrc
ls -la $foo
ls: cannot access '~/.vimrc': No such file or directory

ls -la ~/.vimrc
-rw-r--r-- 1 konczi.ext users 19 Jan  2 12:49 /home/konczi.ext/.vimrc

Fix:
i would replace ~/ or ~ with $HOME value when there is a
variable definition. If \~ is used, no replacement is needed because of
the escaping.



--
Mit freundlichen Grüßen/Kind regards

Istvan Koncz




Istvan Koncz
OEDIV Digital Services (ODS)

OEDIV Oetker Daten- und Informationsverarbeitung KG
Bechterdisser Str. 10
33719 Bielefeld, Germany

phone:   +49 521
fax: +49 521 26050 445
mailto:   istvan.ko...@oediv.de
web:   www.oediv.de


Gesellschaftssitz: Bielefeld
Registergericht: Amtsgericht Bielefeld HRA 13532
Der Umwelt zuliebe: E-Mails und Anhänge nur ausdrucken, wenn unbedingt 
nötig.
Save paper - print e-mails and attachments only when absolutely necessary.

_

Dieses E-Mail kann Informationen enthalten, die vertraulich sind und/oder 
dem Berufsgeheimnis unterfallen.
Diese Information ist nur für den Gebrauch durch die in diesem E-Mail 
benannte Person oder Rechtseinheit
bestimmt. Jede(r) unautorisierte Durchsicht, Gebrauch, Verwendung, 
Offenlegung oder Verbreitung ist verboten.
Falls Sie nicht der beabsichtigte Empfänger sind, bitten wir Sie, den 
Absender durch Antwort E-Mail zu
benachrichtigen und das empfangene E-Mail dauerhaft zu löschen sowie alle 
Kopien hiervon zu vernichten.
Vielen Dank.
Da über das Internet versandte E-Mails während des Übermittlungsprozesses 
leicht verfälscht und/oder unter
fremden Namen erstellt werden können, übernehmen wir keine Verantwortung 
für den Inhalt der E-Mail oder der
Anhänge und folglich kann der Inhalt des E-Mails kein rechtlich bindendes 
Angebot und keine rechtlich
bindende Annahme eines Angebots begründen sofern nicht ausdrücklich 
schriftlich anders vereinbart. Diese
E-Mail dient ausschließlich dem Informationsaustausch. Es gelten unsere 
Allgemeinen Geschäftsbedingungen.
Wir unternehmen alle Anstrengungen, um unser Netzwerk von Viren 
freizuhalten. Dennoch sollten Sie dieses
E-Mail und seine Anhänge auf Viren überprüfen, da wir keine Verantwortung 
für Computerviren übernehmen,
die durch dieses Mail unbeabsichtigt übermittelt werden könnten.

This e-mail may contain information that is confidential and/or privileged. 
This information is intended only
for the use of the individual or entity named in this e-mail. Any 
unauthorized review, use, disclosure or
distribution is prohibited. If you are not the intended recipient, please 
immediately contact the sender by
reply e-mail and permanently d

Re: tilde character not interpreted in variable set

2018-03-02 Thread Chet Ramey
On 3/2/18 7:14 AM, Koncz, Istvan (Extern) wrote:

> Bash Version: 4.4
> Patch Level: 18
> Release Status: release
> 
> Description:
> when i use ~/ for home folder it works in command line e.g. ls
> -la ~/.vimrc works, but when i add it to a variable e.g. foo="~/.vimrc"
> then ~/ will not be replaced to $HOME value like in command line, but i
> think it should be. ~ is a special character so must be escapped like
> \~ if i want the char, but without escape it should provide the home
> like in ls -la ~/ command. In my oppinion it is a bug.

It's not a bug. The tilde is quoted, and is not one of the special
characters that is interpreted inside double quotes.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/