Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To do literally what you said, you could try:</p> <pre><code>ls &gt; `pwd`.txt </code></pre> <p>which will use the full pathname, which should be fine. Note that if you do this in your home directory, which might be in /home/hoboben, you will be trying the create /home/hoboben.txt, a text file in the directory above.</p> <p>Is this what you wanted?</p> <p>If you wanted the directory to contain a file named after it, you would get the basename of the current directory and append that with .txt to the pwd.</p> <p>Now, rather than use the pwd command... why not use the PWD environment variable?</p> <p>For example:</p> <pre><code>ls &gt; $PWD.txt </code></pre> <p>or</p> <pre><code>ls &gt; ${PWD}.txt </code></pre> <p>is probably what you were trying to remember with your second example.</p> <p>If you're in /home/hoboben and you want to create /home/hoboben/hoboben.txt, try:</p> <pre><code>ls &gt; ${PWD}/${PWD##*/}.txt </code></pre> <p>If you do this, the file will contain its own name, so most often, you would remedy this in one of a few ways. You could redirect to somewhere else and move the file or name the file beginning with a dot to hide it from the ls command as long as you don't use the -a flag (and then optionally rename the resulting file).</p> <p>I write my own scripts to manage a directory hierarchy of music files and I use subdirectories named ".info", for example, to contain track data in some spare files (basically, I "hide" metadata this way). It works out okay because my needs are simple and my collection small.</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