<p dir="auto">The "cd" function doesn't automatically expand tilde to your home directory, which is somewhat inconvenient, especially for interactive use. Is this an explicit design decision? We could have "cd" just check if ENV["HOME"] is defined, and if so substitute it for ~.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="julia&gt; cd(&quot;~/Desktop&quot;)
ERROR: chdir ~/Desktop: No such file or directory
 in systemerror at error.jl:38
 in cd at file.jl:14"><pre class="notranslate"><code class="notranslate">julia&gt; cd("~/Desktop")
ERROR: chdir ~/Desktop: No such file or directory
 in systemerror at error.jl:38
 in cd at file.jl:14
</code></pre></div>
<p dir="auto"><a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/timholy/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/timholy">@timholy</a> implemented <code class="notranslate">tilde_expand</code> (see <a href="https://github.com/JuliaLang/julia/blob/master/base/file.jl#L99">file.jl</a>) some time ago and it is now used automatically by a few file-system commands, notably <code class="notranslate">cd()</code>. This concerns me, however, since while it's convenient for some things, it's inconsistently used, and it violates the treatment of strings as just data. What if the name of a file is just <code class="notranslate">~</code>? We're now in a position where that name needs to be escaped and handled specially in code. On the other hand, tilde expansion is awfully handy.</p>
<p dir="auto">So here's a possibility: bake tilde expansion into the backtick syntax instead. For example, we could make this work:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; run(`tail ~/.julia_history`)
           error(&quot;~user tilde expansion not yet implemented&quot;)
       end
tilde_expand(&quot;~&quot;)
tilde_expand(&quot;~/foo&quot;)
tilde_expand(&quot;~stefan/foo&quot;)
tilde_expand(&quot;~stefan&quot;)
`cat ~/.julia`
run(`cat ~/.julia`)
run(`tail ~/.julia_history`)
run(`tail $(ENV[&quot;HOME&quot;])/.julia_history`)"><pre class="notranslate">julia<span class="pl-k">&gt;</span> <span class="pl-c1">run</span>(<span class="pl-s"><span class="pl-pds">`</span>tail ~/.julia_history<span class="pl-pds">`</span></span>)
           <span class="pl-c1">error</span>(<span class="pl-s"><span class="pl-pds">"</span>~user tilde expansion not yet implemented<span class="pl-pds">"</span></span>)
       <span class="pl-k">end</span>
<span class="pl-c1">tilde_expand</span>(<span class="pl-s"><span class="pl-pds">"</span>~<span class="pl-pds">"</span></span>)
<span class="pl-c1">tilde_expand</span>(<span class="pl-s"><span class="pl-pds">"</span>~/foo<span class="pl-pds">"</span></span>)
<span class="pl-c1">tilde_expand</span>(<span class="pl-s"><span class="pl-pds">"</span>~stefan/foo<span class="pl-pds">"</span></span>)
<span class="pl-c1">tilde_expand</span>(<span class="pl-s"><span class="pl-pds">"</span>~stefan<span class="pl-pds">"</span></span>)
<span class="pl-s"><span class="pl-pds">`</span>cat ~/.julia<span class="pl-pds">`</span></span>
<span class="pl-c1">run</span>(<span class="pl-s"><span class="pl-pds">`</span>cat ~/.julia<span class="pl-pds">`</span></span>)
<span class="pl-c1">run</span>(<span class="pl-s"><span class="pl-pds">`</span>tail ~/.julia_history<span class="pl-pds">`</span></span>)
<span class="pl-c1">run</span>(<span class="pl-s"><span class="pl-pds">`</span>tail $(ENV["HOME"])/.julia_history<span class="pl-pds">`</span></span>)</pre></div>
<p dir="auto">Currently this just looks for a file literally named <code class="notranslate">~/.julia_history</code>. Obviously, this would be handy for entering commands, but you could also use it in situations where you want shell-like treatment of any string. For example <code class="notranslate">cd(</code>~<code class="notranslate">)</code> would expand to <code class="notranslate">cd(ENV["HOME"])</code> whereas <code class="notranslate">cd("~")</code> would treat its argument literally. Very importantly, tilde expansion would be done at compile time, not based on the run-time data — this is essential to avoiding nasty surprises and corner cases. In particular, interpolated values are not tilde expanded:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; `~`
`/Users/stefan`

julia&gt; file = &quot;~&quot;;

julia&gt; `$file`
`~`"><pre class="notranslate">julia<span class="pl-k">&gt;</span> <span class="pl-s"><span class="pl-pds">`</span>~<span class="pl-pds">`</span></span>
<span class="pl-s"><span class="pl-pds">`</span>/Users/stefan<span class="pl-pds">`</span></span>

julia<span class="pl-k">&gt;</span> file <span class="pl-k">=</span> <span class="pl-s"><span class="pl-pds">"</span>~<span class="pl-pds">"</span></span>;

julia<span class="pl-k">&gt;</span> <span class="pl-s"><span class="pl-pds">`</span>$file<span class="pl-pds">`</span></span>
<span class="pl-s"><span class="pl-pds">`</span>~<span class="pl-pds">`</span></span></pre></div>
<p dir="auto">One corollary of this approach is that file and directory operations have to work with <code class="notranslate">Cmd</code> objects, which maybe ought to be renamed in light of their broadened use-cases under this proposal. Maybe they should be called <code class="notranslate">ShellString</code> objects since backtick strings are basically strings with shell-like behavior. Except that they're also not strings, so maybe that's not a great name either.</p>