PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Unterschied zwischen ~ und $HOME?



Meillo
02.06.05, 12:53
Gibt's denn einen Unterschied zwischen z.B.
~/dir/file
und
$HOME/dir/file
?
Und wenn, welcher?

Freekazonid
02.06.05, 13:00
bash-2.05b$ echo $HOME
/home/freeka
bash-2.05b$ echo ~
/home/freeka
bash-2.05b$


ergo kein unterschied :D

xeroc
02.06.05, 13:19
oder auch so:


xeroc@xeroc ~ $ echo $HOME
/home/xeroc
xeroc@xeroc ~ $ export HOME=/files
xeroc@xeroc xeroc $ echo $HOME
/files
xeroc@xeroc xeroc $ echo ~
/files
xeroc@xeroc xeroc $

sirmoloch
02.06.05, 14:00
Siehe man bash:


Tilde Expansion
If a word begins with an unquoted tilde character (`~'), all of the characters preceding the
first unquoted slash (or all characters, if there is no unquoted slash) are considered a
tilde-prefix. If none of the characters in the tilde-prefix are quoted, the characters in
the tilde-prefix following the tilde are treated as a possible login name. If this login
name is the null string, the tilde is replaced with the value of the shell parameter HOME.
If HOME is unset, the home directory of the user executing the shell is substituted instead.
Otherwise, the tilde-prefix is replaced with the home directory associated with the specified
login name.

If the tilde-prefix is a `~+', the value of the shell variable PWD replaces the tilde-prefix.
If the tilde-prefix is a `~-', the value of the shell variable OLDPWD, if it is set, is sub-
stituted. If the characters following the tilde in the tilde-prefix consist of a number N,
optionally prefixed by a `+' or a `-', the tilde-prefix is replaced with the corresponding
element from the directory stack, as it would be displayed by the dirs builtin invoked with
the tilde-prefix as an argument. If the characters following the tilde in the tilde-prefix
consist of a number without a leading `+' or `-', `+' is assumed.

If the login name is invalid, or the tilde expansion fails, the word is unchanged.

Each variable assignment is checked for unquoted tilde-prefixes immediately following a : or
=. In these cases, tilde expansion is also performed. Consequently, one may use file names
with tildes in assignments to PATH, MAILPATH, and CDPATH, and the shell assigns the expanded
value.

Meillo
02.06.05, 14:41
... und welches der Beiden sollte man in Shell-Scripten verwenden - gibt's da Empfehlungen?

da @sirmoloch die Tilde auch anders gesetz sein kann:
If the tilde-prefix is a `~+', the value of the shell variable PWD replaces the tilde-prefix.
... wobei $HOME kann man ja auch verändern ....

fs111
04.06.05, 13:00
Ich denke mit $HOME fährt man immer besser, da es portabler zwischen verschiedenen Shells und Systemen ist.

fs111

stefan.becker
04.06.05, 13:05
Ich denke mit $HOME fährt man immer besser, da es portabler zwischen verschiedenen Shells und Systemen ist.

Kann ich bestätigen. Das Problem hatte ich bei lxdvdrip. EIn User hatte "~" in den Pfad geschrieben. Ergebnis: Es ging nicht. Lösung: $HOME ausgelesen und damit ~ ersetzt, schon geht es.

Meillo
04.06.05, 17:18
danke für die Antworten
wollte mich nur darüber vergewissern, bevor ich in's Shellscripting einsteige ;)