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
2
votes
1 answer

Can't use folder path with tilde in rmdir

I need to be able to remove a directory that is relative to the Documents folder of any user's system. rmdir: ~/Documents/Folder: No such file or directory If I manually enter the expanded path (/Users/ricky/Documents/Folder), it works fine. I…
Ricky
  • 3,101
  • 1
  • 25
  • 33
2
votes
2 answers

combining tilde expansion with variable substitution in bash

Say I'm running bash as root, and I want to chown the home directory of a user ada. Say also that ada is stored in a variable called $USER (because I'm doing this from a script). When I tried the following, chown -R $USER:$USER ~$USER the shell…
2
votes
1 answer

When does the slash in a Linux path need to be outside quotes in a bash script

Why does the first expansion not work, yet the second does? I know tilde has to be expanded outside quotes but the slash also had to be outside, unexpectedly. #!/bin/bash ls ~"/Documents/bashscripts/test.sh" ls ~/"Documents/bashscripts/test.sh"
H2ONaCl
  • 10,644
  • 14
  • 70
  • 114
2
votes
4 answers

is there any way to make System.IO.Directory.GetFiles(string) look in the program's directory?

I'm trying to use string[] files = System.IO.Directory.GetFiles("~/Pictures/"); to search a folder in the program for picture files. This will later be used to randomly select a picture to display in an image box.I get an error when it tries to…
Craig Smith
  • 583
  • 3
  • 9
  • 26
1
vote
1 answer

Way to Perform Tilde-Expansion on Every Path Evaluated by Python OS Module?

I'm running Linux, and would like for my project to replace the tilde character, '~', at the beginning of a path with my home directory, in the same way the terminal does. I've found a method of the os module that achieves this, known as…
MillerTime
  • 317
  • 2
  • 11
1
vote
0 answers

Bash script can't find a file using a if statement with -e

I have a simple bash script that tries to find a folder, and if it can't find it, it gives an error. It gets a argument and tries to find a folder in the .local folder called menu. I have the folder, but it can't find it: Permissions Links Size User…
fg_
  • 59
  • 1
  • 8
1
vote
1 answer

Tilde Expansion Doesn't Work in Docker CMD Command

I have a Dockerfile with the following line: USER lodgepole CMD ["tail", "-f", "~/block.txt"] But container exits with error that the file ~/block.txt is not found The following does work as expected: CMD ["tail", "-f",…
Yue JIN
  • 1,047
  • 1
  • 10
  • 20
1
vote
0 answers

Bash hangs in Cygwin on tilde-number

I encountered some bizarre Bash behavior today, and maybe it's a bug that's since been fixed, but I'm going to ask about it anyway. I have an x64 Cygwin install on my work computer with Bash 4.3.46 in it. By accident today, instead of typing !533…
Sean Werkema
  • 5,810
  • 2
  • 38
  • 42
1
vote
1 answer

Can't use tilde (~) for sed -i backup character on OSX: "sed: rename(): Not a directory"

On my OSX machine, I can't use ~ as the backup character for in-place sed. Any other character is fine. The error I get is... cryptic: rename(): Not a directory. Example: $ echo foo > bar $ sed -i ~ -e s/foo/hello/ bar sed: rename(): Not a…
hraban
  • 1,819
  • 1
  • 17
  • 27
1
vote
1 answer

R: Is there a way to specify TMPDIR in .Renviron based on $HOME or ~?

I am looking for a simple student-proof way to specify a custom TMPDIR in R sessions. R seems unable to expand ~ or $USER, so if I simply write TMPDIR=~/tmp or TMPDIR=$HOME/tmp in .Renviron it does not find the folder, and uses /tmp instead, which…
ggll
  • 963
  • 10
  • 13
1
vote
1 answer

Getting short path for ssh

I'm writing a shell script to be used with ssh/git. I want to get the present directory relative to home, if possible. The goal is to get the shortest path to be used with ssh, that is the path in context of the user. For example, if my working…
Jonathan Allard
  • 18,429
  • 11
  • 54
  • 75
0
votes
1 answer

Collapsing home folder in path to tilde character

In Swift, abbreviatingWithTildeInPath creates “a new string that replaces the current home directory portion of the current path with a tilde (~) character”. In other words, it turns /Users/username/Desktop/ into ~/Desktop. In Ruby we can do the…
user137369
  • 5,219
  • 5
  • 31
  • 54
0
votes
1 answer

How can I get my script to recognize a file path?

So, I am making what I thought was a simple script to move multiple files to a new location. I wanted is to ask where the files were going. So I type in something like ~/i/want/to/go/here after the prompt. and the script can't seem to see it as…
0
votes
0 answers

How can I make bash realpath work with variables?

I run #!/bin/bash id="~/.ssh/foo" realpath ~/.ssh/foo realpath "~/.ssh/foo" realpath $id realpath "$id" expecting 4 identical lines of output, with no errors. What I get is /home/me/.ssh/foo realpath: '~/.ssh/foo': No such file or…
spraff
  • 32,570
  • 22
  • 121
  • 229
0
votes
1 answer

Stop tilde expansion in bash script arguments

Consider this tiny script: # script.sh echo $@ If I call it like this ./script.sh ~/docs, I get /home/me/docs as output. However, I need it to echo ~/docs. How can I achieve that?
coderodde
  • 1,269
  • 4
  • 17
  • 34