Live data from Hacker News

The Art of Command Line

github.com

41–50 of 134 posts

Re: The Art of Command Line

#41
post #24

> StrictHostKeyChecking=no And welcome to MITM haven. This is awful advice if you care about the first S in SSH.

Depends on your circumstances, really. If you're in an environment with lots of VM's floating around, being created, destroyed, and so on, dealing with SSH's paranoia (why can't I just dismiss a warning about a host/key mismatch instead of having to edit .known_hosts?) quickly becomes an exercise in frustration for dubious security benefit. (If the enemy is on your LAN and able to manipulate your DNS, you've already lost)

On your home box, sure. But let's not pretend there's not a reason for the option to exist.

Re: The Art of Command Line

#43
post #15

If you learn bash, and you learn vi, then the next most glorious addition is: set -o vi Then you have vi keys in your shell. And it is marvelous.

Can you share a little more info about this? I tried it but found it rather confusing.

Also, for more readline maneuvers: http://unix.stackexchange.com/questions/21788/how-to-delete-...

Re: The Art of Command Line

#44
post #9
post #4

There's no reason to learn vi if you know Emacs. If you claim that Emacs isn't installed everywhere, guess what: Neither is vi. If you want an "installed everywhere" editor, learn ed. If you're willing to take an editor with you (or otherwise make sure a specific editor is everywhere you are), there's no reason it has to be vi.

vi is a posix requirement, emacs is not. If the system you're working on has ed, it'll have some version of vi or vim as well.

I don't think this is true. I've certainly been in a bunch of hairy situations over the years where I had nothing fancier than ed available to me because I was in some sort of recovery mode. The single user mode that FreeBSD comes with is lacking vi if, for example, you don't have / mounted yet. Thankfully ed is in the ramdisk.

Re: The Art of Command Line

#45
post #37
post #27

Earlier quoted context omitted.

How is ASCII or Latin-1 somehow not an obscure encoding scheme by your parlance? Latin-1 is less common by quite a bit on the web than UTF-8, and ASCII might be if UTF-8 wasn't a superset. Fact of the matter is people have to get out of the habit of going "oh, that will never be relevant for me", because a) that's unlikely to be true for everybody (for example in a server environment you can't even write perfectly go…

The original question was about the command line. When managing servers it's perfectly accessible to use LATIN1 if one does not expect to deal with UTF-8 data (examining processes, VM states, changing configuration, etc). If that's not the case, one can use UTF-8 or some other encoding for that matter (i.e. I routinely have to deal with non-UTF non-ASCII filenames and text, using UTF-8 won't cut here either).

> if one does not expect to deal with UTF-8 data

This is a horrible assumption. UTF8 can show up just about anywhere. 99% of the utilities mentioned in the article support UTF8, which means they will output UTF8 if they think that's a good idea. And that can show up at any point. Exotic filenames, error messages, fancy boxing or indicative characters in the output...

Don't expect Latin-1, ever. Respect specified encodings, and default to UTF8. Never, ever think you'll be fine with Latin-1 when dealing with an UTF-8 output just because you speak english.

The trick the original article specified is a hack to get better performance in very controlled situations, it should never be put in a rc file like it recommends because it will break and you won't know that is what's causing it.

Edit: Here's a few examples of very real potential breakage, to show you how bad an idea this is: You're debugging a python script. You open a python shell and start pasting some of its lines to figure out what's happening. OOPS, there's UTF-8 in there.

    [4:08:48] adys@azura ~ % python -c 'print("I like the letter Š")' 
    I like the letter Š
    [4:08:54] adys@azura ~ % LANG=C python -c 'print("I like the letter Š")'
    Unable to decode the command from the command line:
    UnicodeEncodeError: 'utf-8' codec can't encode character '\udcc5' in position 25: surrogates not allowed
(The input doesn't even have to be explicit, by the way, it could even be in your filenames).

Should I keep going? See how "awk '{print tolower($0)}'" behaves when it's dealing with utf-8 input. Maybe that awk is deeply hidden in a 5000 line script. Maybe it deals with web data, filenames, anything. And suddenly you have unicode escapes in data that doesn't expect any.

Now how's that one line in your rc file, which you wrote maybe months or years ago, working out for you? Are you going to know the issue is your LC_ALL variable?

Re: The Art of Command Line

#46

> To disable slow i18n routines and use traditional byte-based sort order, use export LC_ALL=C (in fact, consider putting this in your ~/.bashrc). Do not. Having a non-utf8 locale means you won't be able to handle utf-8 sanely ("that's why it's faster") and it will break at the most inexplicable times. Any non-latin1 character appearing in your prompt or command line with this will mess its spacing up for example. Do…

I have the following set in my .cshrc: setenv LC_ALL en_US.UTF-8 setenv LC_COLLATE C # use the ASCII sort order What have I broken, and how badly?

You're not breaking anything on a technical level with that. Be wary of anything that deals with string or character comparison however (including regexes).

Re: The Art of Command Line

#47
post #15

If you learn bash, and you learn vi, then the next most glorious addition is: set -o vi Then you have vi keys in your shell. And it is marvelous.

Can you share a little more info about this? I tried it but found it rather confusing. Also, for more readline maneuvers: http://unix.stackexchange.com/questions/21788/how-to-delete-...

`set -o vi` allows us to use `vi` bindings instead of the default `emacs` bindings.

The way to think about it is that the prompt starts out in `vi insert mode` so whatever we type in will just be inserted at the prompt. However, we can hit the`Escape` key and move into `vi normal mode` where the keys are interpreted as normal `vi` commands. So, for example, once we hit `esc` we can navigate around the line using `h` and `l` and navigate history (previous lines) using `k` and `j`.

Commands I find very useful are:

`jk` : for history navigation

`bw`: for moving in the current line. These are word movement commands that are faster to navigate with.

`cw` : similarly, changing a particular word in the current line is also great. This works particularly well with history - retrieve a previous command and change a word or option

`dw` : for deleting the current word

`/` : is a fantastic command for searching history. `/cd` will bring up our last change directory command and just hitting `n` will cycle through all our change directory commands that are in history.

`AI` : to insert at the beginning/end of line

...and so on. If you have `vi` muscle memory it's a fantastic option for working on the shell.

(edit: Formatting)

Re: The Art of Command Line

#49
post #4

There's no reason to learn vi if you know Emacs. If you claim that Emacs isn't installed everywhere, guess what: Neither is vi. If you want an "installed everywhere" editor, learn ed. If you're willing to take an editor with you (or otherwise make sure a specific editor is everywhere you are), there's no reason it has to be vi.

I can't remember ever encountered a unix-like system without "vi" installed. I've used (and set up) machines running FreeBSD, DragonflyBSD, OSX, Ubuntu, Debian, RHEL, ... Plenty of those didn't have emacs, especially on first boot, when you're most likely to need to modify network configuration files in order to get online to install new packages in the first place... Edit: By "vi" I mean that somewhere in the path t…

> I can't remember ever encountered a unix-like system without "vi" installed.

Default Ubuntu install.

Re: The Art of Command Line

#50
post #9
post #4

There's no reason to learn vi if you know Emacs. If you claim that Emacs isn't installed everywhere, guess what: Neither is vi. If you want an "installed everywhere" editor, learn ed. If you're willing to take an editor with you (or otherwise make sure a specific editor is everywhere you are), there's no reason it has to be vi.

vi is a posix requirement, emacs is not. If the system you're working on has ed, it'll have some version of vi or vim as well.

Not in Ubuntu.
Post reply on HN