LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-23-2002, 07:40 PM   #1
ChimpFace9000
Member
 
Registered: Jul 2001
Location: So. Cal.
Distribution: Slackware 8.1
Posts: 55

Rep: Reputation: 15
Post ~, kernel or shell?


The "~" means your home directory right. Well is that a part of the bash shell or part of the linux kernel? What i mean is, if i type "cd ~", does bash change the "~" into a string containg my home directory and pass that string on to the "cd" program. Or does it pass the actual "~" character to "cd", and "cd" passes it to the kernel, and the kernel changes it to my home directory?

Let me know if i didnt make any sense.
 
Old 04-24-2002, 04:27 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
it's part of bash. you don't need to do that in case you didn't know. just using "cd" with no params will take you home
 
Old 04-24-2002, 07:11 AM   #3
Thymox
Senior Member
 
Registered: Apr 2001
Location: Plymouth, England.
Distribution: Debian + Ubuntu
Posts: 4,358

Rep: Reputation: 57
I found it's quite a good habit to get into, though. cd may take you home, but cd files will not take you to ~/files, whereas cd ~/files will. Just me being a little anal.
 
Old 04-25-2002, 10:18 AM   #4
abrakadabra
Member
 
Registered: Apr 2002
Location: Denver
Distribution: SuSe,RedHat,Mandrake,
Posts: 109

Rep: Reputation: 16
Post

Hi,
I don't have an exact answer for this, but this is what I found out. The tilde (~) holds the value of $HOME, so ~=$HOME.
I'd say that ~ is at the kernel level since trying to give it a value other than $HOME is not possible, at least on my testing trying to make changes to it and give it another value. So, I'd say that
when we type ~ at the command prompt the kernel immediately "knows" that this is actually $HOME comming from the shell.
I did not find anything more specific on this.

 
Old 04-25-2002, 05:48 PM   #5
DMR
Member
 
Registered: Jun 2001
Location: Fairfax, California
Distribution: RH 9.0, RH 7.3, Mandrake 8.0
Posts: 986

Rep: Reputation: 30
Actually, tilde expansion and the HOME environment variable are both functions of the shell. The value of $HOME is set to the home dir of the user who spawns the shell, and the tilde will be expanded by the shell to that value.If the value of $HOME is changed, the tilde will expand to the new value:
Code:
[root@Boris /etc]# echo $HOME
/root
[root@Boris /etc]# cd ~
[root@Boris /root]# export HOME=bogus
[root@Boris /root]# echo $HOME
bogus
[root@Boris /root]# cd ~
bash: cd: bogus: No such file or directory
[root@Boris /root]# export HOME=/root
[root@Boris /root]# echo $HOME
/root
[root@Boris /root]#
The tilde can be expanded to other values however, including:
The Home directory of another user
Code:
[root@Boris /root]# pwd
/root
[root@Boris /root]# cd ~Dave
[root@Boris Dave]# pwd
/home/Dave
[root@Boris Dave]#
or the value of $PWD
Code:
[root@Boris /]# pwd
/
[root@Boris /]# cd ~+/usr
[root@Boris usr]# pwd
/usr
[root@Boris usr]#
~Fun with Bash

Last edited by DMR; 04-25-2002 at 05:51 PM.
 
Old 04-25-2002, 06:26 PM   #6
abrakadabra
Member
 
Registered: Apr 2002
Location: Denver
Distribution: SuSe,RedHat,Mandrake,
Posts: 109

Rep: Reputation: 16
Lightbulb

DMR,
Thanks for your input on this. Not only I assumed that it was not possible but also proved my theory to be wrong. Which is fine because I should know better that if there is Linux there is a way!

 
Old 04-25-2002, 07:22 PM   #7
DMR
Member
 
Registered: Jun 2001
Location: Fairfax, California
Distribution: RH 9.0, RH 7.3, Mandrake 8.0
Posts: 986

Rep: Reputation: 30
Quote:
Originally posted by abrakadabra
if there is Linux there is a way!
lol, The new motto of the geek generation!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between normal shell and login shell Manish Linux - General 7 11-14-2012 09:30 AM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 03:14 AM
what is kernel, shell? can help me understand the concept as compared to microsoft wi zhuzhu Debian 2 11-16-2005 08:16 PM
'sh' shell - Actually calls legacy Bourne shell, or uses system default? Dtsazza Linux - Software 1 10-28-2005 10:20 AM
How to find out kernel version in a shell script? ta0kira Slackware 3 10-05-2004 05:54 AM


All times are GMT -5. The time now is 02:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration