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'
55 questions
157
votes
16 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,447
  • 4
  • 19
  • 15
52
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
  • 36,164
  • 38
  • 101
  • 131
21
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,198
  • 5
  • 18
  • 19
12
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
  • 13,471
  • 6
  • 43
  • 61
10
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.
  • 8,707
  • 7
  • 39
  • 64
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…
Ben Leggiero
  • 25,904
  • 38
  • 161
  • 267
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,688
  • 3
  • 29
  • 46
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
  • 915
  • 1
  • 11
  • 15
5
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
  • 307
  • 1
  • 4
  • 17
5
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
  • 26,728
  • 46
  • 126
  • 177
5
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
  • 67
  • 1
  • 7
5
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
  • 51
  • 1
  • 2
5
votes
1 answer

shell tilde expansion does not work when passed as an option

I find tilde expansion does not work for the following situation: $ set -x $ ./print_arg.pl destdir=~/test + ./print_arg.pl 'destdir=/root/test' destdir=/root/test $ ./print_arg.pl dest-dir=~/test + ./print_arg.pl…
lisper
  • 75
  • 6
4
votes
1 answer

Tilde-based Paths in Objective-C

In Objective-C, how do I go about converting tilde-based pathnames to full pathnames? That is, I'd like to convert from ~/sandbox to /Users/TheBobs/sandbox.
zanussi
  • 1,237
  • 2
  • 25
  • 29
4
votes
1 answer

cygwin tilde expansion not working in interactive shell

For some reason tilde expansion in Cygwin is not working for me at the prompt: $ ls ~ ls: cannot access : No such file or directory $ ls ~/bin (lists /bin not $HOME/bin) $ echo $HOME /home/myusername $ echo ~ $ In the last case there (echo ~)…
ErikR
  • 50,049
  • 6
  • 66
  • 121
1
2 3 4