Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The options for any command line are expanded before the command is run, even for internal commands. Whatever shell you're using to run <code>/bin/bash cd ~</code> is presumably interpreting the tilde literally rather than a special character that expands to your home directory.</p> <p>As a test, try creating a directory by that name and see if the error goes away.</p> <pre><code>&gt; mkdir ./~ &gt; /bin/bash cd ~ </code></pre> <p>Note that the <code>cd</code> command needs to be done <em>within your running shell</em> to be useful. When you change the working directory of a sub-shell, and then the sub-shell exits, you'll find yourself back where you started.</p> <p><strong>UPDATE</strong>:</p> <p>From within a bash script, you should be able to use the <code>$HOME</code> environment variable, which should consistently contain your home directory. I'm not aware what conditions would cause tilde expansion to fail, but I've always used <code>$HOME</code>.</p> <p>Also, when determining whether you can change into a particular directory, you have the option of being explicit and returning useful status:</p> <pre><code>unset err if [[ ! -d "$somedir" ]]; then err="Can't find $somedir" elif [[ ! -r "$somedir" ]]; then err="Can't read $somedir" fi if [[ -n "$err" ]]; then echo "$ERROR: $err" &gt;&amp;2 exit 1 fi cd "$somedir" </code></pre> <p>Or, you can just try the CD and look at its results.</p> <pre><code>if ! cd "$somedir"; then echo "ERROR: $somedir not availble" exit 1 fi </code></pre> <p>Detailed error reports are handy, but if you don't need them, keeping your code small has advantages as well.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload