Questions tagged [tilde-expansion]

Tilde expansion is a feature of the POSIX shell providing shortcut access to users' home directories.

Tilde expansion is a feature of POSIX shells providing shortcuts for the users' home directories:

~ # current user's home directory
~bob # home directory of the user named 'bob'
67 questions
190
votes
19 answers

How to manually expand a special variable (ex: ~ tilde) in bash

I have a variable in my bash script whose value is something like this: ~/a/b/c Note that it is unexpanded tilde. When I do ls -lt on this variable (call it $VAR), I get no such directory. I want to let bash interpret/expand this variable without…
madiyaan damha
  • 2,917
  • 5
  • 21
  • 15
55
votes
6 answers

How do I find a user's home directory in Perl?

I need to check whether a file in a user's home directory exists so use file check: if ( -e "~/foo.txt" ) { print "yes, it exists!" ; } Even though there is a file called foo.txt under the user's home directory, Perl always complains that there…
Haiyuan Zhang
  • 40,802
  • 41
  • 107
  • 134
40
votes
3 answers

Why use $HOME over ~ (tilde) in a shell script?

Is there any reason to use the variable $HOME instead of a simple ~ (tilde) in a shell script?
25
votes
5 answers

Tilde in path doesn't expand to home directory

Say I have a folder called Foo located in /home/user/ (my /home/user also being represented by ~). I want to have a variable a="~/Foo" and then do cd $a I get -bash: cd: ~/Foo: No such file or directory However if I just do cd ~/Foo it works fine.…
Benjamin
  • 2,718
  • 5
  • 21
  • 20
20
votes
1 answer

Why is a tilde in a path not expanded in a shell script?

I tried to get the Android Studio launcher (studio.sh) to use my manually installed Java (not the system-wide default Java). Since I already declared PATH and JAVA_HOME in my .bashrc file, I simply sourced that file in the shell script: .…
user2633841
18
votes
1 answer

Tilde Expansion Doesn't Work in Docker COPY Command

I have a Dockerfile with the following line: COPY *.zip ~user1 The user user1 already exists and has a home directory (i.e. /home/user1). The goal, of course, is to copy the zip file into that user's home dir, however the result of the above is…
Dave L.
  • 9,595
  • 7
  • 43
  • 69
16
votes
4 answers

Swift: How to expand a tilde in a path String

How can I expand a path String with a tilde in Swift? I have a string like "~/Desktop" and I'd like to use this path with the NSFileManager methods, which requires the tilde to be expanded to "/Users//Desktop". (This question with a clear…
Kametrixom
  • 14,673
  • 7
  • 45
  • 62
10
votes
2 answers

tilde expansion in environment variable

In my .sh file, I have this, cp $file $SOME_PATH, while $SOME_PATH is exported as export SOME_PATH="~/path/to/path/". But when I ran this .sh file, I got error message saying like no such "~/path/to/path/" exists. I replaced ~ as $HOME, then the…
dutor
  • 137
  • 1
  • 6
7
votes
6 answers

How can I make Perl recognize paths with '~'?

Possible Duplicate: How do I find a user's home directory in Perl? I'm running Ubuntu. Whenever I pass a Perl script a path that starts with ~ (e.g. ~/Documents/file.txt) it fails finding it. I must pass the canonical path (e.g.…
David B
  • 29,258
  • 50
  • 133
  • 186
6
votes
1 answer

Can I use environment variables or tilde in module.modulemap?

My module.modulemap file looks like this: module CompanyInternalSDK { header "~/Company/CompanyInternalSDK.framework/Headers/CompanyInternalSDK.h" export * } However, I get this…
Ky -
  • 30,724
  • 51
  • 192
  • 308
6
votes
1 answer

Why isn't tilde (~) expanding inside double quotes?

I want to check whether or not the hidden .git folder exists. First thought was to use: if [ -d "~/.git" ]; then echo "Do stuff" fi But the -d apparently does not look for hidden folders.
Swifting
  • 449
  • 1
  • 5
  • 19
6
votes
3 answers

Tilde "~" expression not functioning in "R"?

The tilde expression is not working on my RStudio! I am using a windows 10 OS. Update : After looking more carefully(thanks to Dason) It seems the "~" is pointing to "user/Documents/" rather then "user/". is there any work around? Any help?
data9
  • 77
  • 1
  • 7
6
votes
4 answers

Why can't QFile read from the "~" directory?

I've tried the following short example to find out about a bug in a bigger program I am working on. It looks like QFile doesn't support unix (or the shell's) notation for the home directory: #include #include int main() { …
hurikhan77
  • 5,881
  • 3
  • 32
  • 47
6
votes
6 answers

have to determine all users home directories - tilde scripting problem

Assume someuser has a home directory /home/someuser NAME=someuser In bash - what expression to I use combining tilde (~) and $NAME to return the users home directory? HOMEDIRECTORY=~someuser echo $HOMEDIRECTORY /home/someuser NAME=someuser echo…
iaroot
  • 61
  • 1
  • 2
6
votes
1 answer

ln complains about no such file or directory

I'm new in shell programming on macosx and have a little problem. I've written the following shell script: #!/bin/sh function createlink { source_file=$1 target_file="~/$source_file" if [[ -f $target_file ]]; then rm $target_file fi ln…
Jan Baer
  • 1,105
  • 1
  • 12
  • 15
1
2 3 4 5