LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   tilde symbol for what purpose (https://www.linuxquestions.org/questions/linux-newbie-8/tilde-symbol-for-what-purpose-404302/)

Karthikeyan Gurusamy 01-16-2006 11:22 PM

tilde symbol for what purpose
 
Hi All,

Can anybody pl. tell me, if tilde symbol displays at linux prompt, what does it mean?
Is it default symbol of any shell?

regards,

karthik

T.Hsu 01-16-2006 11:38 PM

Quote:

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 substituted. 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 the first =. 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.
from bash manpage, also

Quote:

PROMPTING
When executing interactively, bash displays the primary prompt PS1 when it is ready to read a command, and the secondary prompt PS2 when it needs more input to complete a command. Bash allows these prompt strings to be customized by inserting a number of backslash-escaped special characters that are decoded as follows:


\a
an ASCII bell character (07)
\d
the date in "Weekday Month Date" format (e.g., "Tue May 26")
\D{format}
the format is passed to strftime(3) and the result is inserted into the prompt string; an empty format results in a locale-specific time representation. The braces are required
\e
an ASCII escape character (033)
\h
the hostname up to the first `.'
\H
the hostname
\j
the number of jobs currently managed by the shell
\l
the basename of the shell's terminal device name
\n
newline
\r
carriage return
\s
the name of the shell, the basename of $0 (the portion following the final slash)
\t
the current time in 24-hour HH:MM:SS format
\T
the current time in 12-hour HH:MM:SS format
\@
the current time in 12-hour am/pm format
\A
the current time in 24-hour HH:MM format
\u
the username of the current user
\v
the version of bash (e.g., 2.00)
\V
the release of bash, version + patch level (e.g., 2.00.0)
\w
the current working directory, with $HOME abbreviated with a tilde
\W
the basename of the current working directory, with $HOME abbreviated with a tilde
\!
the history number of this command
\#
the command number of this command
\$
if the effective UID is 0, a #, otherwise a $
\nnn
the character corresponding to the octal number nnn
\\
a backslash
\[
begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
\]
end a sequence of non-printing characters
hope these answer your question, and "man" is your true friend.

IBall 01-16-2006 11:41 PM

The ~ character is normally a shortcut to your home directory. You can use it instead of typing /home/karthik in a shell.

EG:
cd ~ will take you to your home directory
ls ~/bin will list the contents of the bin directory in your home.

--Ian

Karthikeyan Gurusamy 01-17-2006 12:27 AM

Thanks a lot
 
Thanks a lot friends!!!!

regards,

karthik

timmeke 01-17-2006 04:22 AM

IBall, in most shells, you can go even one step further:
~ian/ represents the home directory of user "ian", for example.


All times are GMT -5. The time now is 03:50 AM.