Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Fri 21 Sep 2018, 06:12
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
What's the difference between these Bash expressions?
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [3 Posts]  
Author Message
Dry Falls

Joined: 16 Dec 2014
Posts: 571
Location: Upper Columbia

PostPosted: Thu 21 Jun 2018, 04:25    Post subject:  What's the difference between these Bash expressions?  

Can anyone tell me the difference between ...
    ${HOME}
    $HOME
    ~/

I think they all point to the user's root directory (spot = /home/spot; root = /root)
What do the brackets do?

thanks,
df
Back to top
View user's profile Send private message 
step

Joined: 04 May 2012
Posts: 1085

PostPosted: Thu 21 Jun 2018, 05:47    Post subject:  

In this case the brackets do nothing. In other cases they can serve to
1. separate the variable name from other text: ${HOME}less -> "/rootless" vs $HOMEless -> ""
2. introduce various ways to transform the variable value, i.e., ${HOME/oo/an} -> "/rant"

Note that the above discussion assumes that HOME is preset to "/root" for the root user - there can be cases when such isn't the case.

The bash shell expands ~ to the user's home directory, in this example "/root". But other shells don't do that kind of expansion, so ~ -> "~" for those shells. Bash also expands ~root to root's home directory, and more generically ~User to User's home directory for any User. Be careful relying on the ~ expansion in your scripts, because the rules for expanding ~ differ from the rules for expanding regular variables, such as HOME.

_________________
Fatdog64-721|+Packages|Kodi|Findnrun|+forum|gtkmenuplus
Back to top
View user's profile Send private message 
Dry Falls

Joined: 16 Dec 2014
Posts: 571
Location: Upper Columbia

PostPosted: Mon 25 Jun 2018, 14:34    Post subject:  

step wrote:
In this case the brackets do nothing. In other cases they can serve to
1. separate the variable name from other text: ${HOME}less -> "/rootless" vs $HOMEless -> ""
2. introduce various ways to transform the variable value, i.e., ${HOME/oo/an} -> "/rant"

Note that the above discussion assumes that HOME is preset to "/root" for the root user - there can be cases when such isn't the case.

The bash shell expands ~ to the user's home directory, in this example "/root". But other shells don't do that kind of expansion, so ~ -> "~" for those shells. Bash also expands ~root to root's home directory, and more generically ~User to User's home directory for any User. Be careful relying on the ~ expansion in your scripts, because the rules for expanding ~ differ from the rules for expanding regular variables, such as HOME.

Thanks Step. This makes sense. I didn't want to have the last word on this thread, but I did want to thank you.

df
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [3 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0327s ][ Queries: 12 (0.0097s) ][ GZIP on ]