20

How can I do the following using the terminal on OS X?

Create a file named .inputrc in a user's home directory and put this line in it:

set completion-ignore-case On

26

Quick Answer

touch ~/.inputrc
echo "set completion-ignore-case On" >> ~/.inputrc

Explanation

First, create the file:

touch ~/.inputrc

Then, add the contents to the file:

echo "set completion-ignore-case On" >> ~/.inputrc

touch creates an empty file (assuming that the ~/.inputrc file does not already exist). echo writes text to the "standard output" ("stdout" for short), which is normally your screen, but because of the redirection (>>), the output is redirected to ~/.inputrc. This setup will append the line to the file.

If ~/.inputrc already exists and you want to erase (clobber) its contents, and then write the line into it (i.e., create a file with only this line of text), do:

echo "set completion-ignore-case On" > ~/.inputrc

The single arrow (>), a.k.a. "greater than" symbol, tells echo to create a file with only the given text as the contents of the file, instead of writing the contents to the end of the file. (Actually, echo does not create the file; the shell creates the file, discarding any existing contents, and the echo command writes the new contents.)


If you use the first approach (with the >>) and you find that the line that you added is smushed onto the previous line, e.g.,

some stuff here
some more stuff hereset completion-ignore-case On

then you need to edit the file to fix it. This would happen if the last line of the pre-existing file ended with a textual character rather than a "newline" character (i.e., an end-of-line marker). This is common for .TXT files on Windows, but rare on *nix.

If you somehow realize in advance that your .inputrc file has pre-existing contents that do not end with a newline, then you should use this echo statement instead:

echo -e "\nset completion-ignore-case On" >> ~/.inputrc

The \n before the phrase is interpreted as a newline character, so a newline is added after the previous contents and before the new stuff you want to add.

Or, slightly more typing but much more readable,

echo "" >> ~/.inputrc
echo "set completion-ignore-case On" >> ~/.inputrc

or

(echo ""; echo "set completion-ignore-case On") >> ~/.inputrc

which do the same thing; i.e., provide the missing newline character to the existing text, and then add the set completion-… command after that.

  • 1
    There is no reason to use the touch command here; echo "…" >> ~/.inputrc is quite enough. – G-Man May 5 '15 at 6:09
  • 1
    Unless the file you want to append to is not existed. – amrx May 7 '15 at 6:05
  • @Baron: No, echo "…" >> ~/.inputrc will create the file if it doesn't exist.  Except for pathological cases, like ~ doesn't exist, you don't have write permission in ~, or the file system is full; and, in such cases, touch won't help.  touch is completely superfluous here. – G-Man May 7 '15 at 20:25
1

All you need to do is:

echo "set completion-ignore-case On" >> ~/.inputrc 

echo simply echos the text given to it through the normal output channel (stdout)

the >> writes the stdout output from the left hand command to the right hand file, which in your case is ~/.inputrc

~/ is the same as /home/your_username/

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.