Live data from Hacker News

Command line tools for the novice

andymatthews.net

21–30 of 59 posts

Re: Command line tools for the novice

#21
> In Grep grep -R 'some term' * , in Ack ack 'some term'. The -R tells grep to search through all directories and subdirectories while the * tells it what types of files.

No, that's not how it works with grep. The shell is expanding the glob * to all the things in the current directory that don't start with a dot and that's what grep sees. It then reads each of them in turn or if they're a directory it descends into them recursively; the * plays no further part in the descent.

Re: Command line tools for the novice

#22
post #20
post #19

Earlier quoted context omitted.

Interesting. I'll give it a go. I've tried living in iPython and eshell, and while I prefer python or lisp as a programming language to almost anything, neither is nearly as quick and dirty as sh for doing stuff with stdin/out from a pipeline of tools. I don't quite know what a better language than sh would look like, but a man can dream. Also, universe, if you're going to get on fixing the sh problem, can we restruc…

Please define "argument expansion".

In many (all?) unix shells, globs are expanded by the shell before being passed to the program.

   'ls *.jpg' 
is passed expanded to 'ls 1.jpg 2.jpg 3.jpg' BEFORE ls is run. This choice means that if a program wants to use another style of regular expression (ie: pcre), it must be enclosed in quotes on the shell, ie:

  "ls | grep -P '.*jpg'"

Re: Command line tools for the novice

#24

Grey text on grey background: http://contrastrebellion.com/

Contrast rebellion refers to W3C's Web Content Accessibility Guidelines, which specify a contrast ratio of at least 4.5. Just for fun, I plugged in the numbers, the site has a contrast ratio of about 4.9.

W3C: http://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contr...

Re: Command line tools for the novice

#25

Earlier quoted context omitted.

This was a good list for the intermediate command line user looking to customize. For the absolute newbie I'd reduce it down to git/hg, ssh, grep/ack and curl. For crazy power users, I'm a huge fan of vim+tmux+zsh combo as described in http://www.drbunsen.org/text-triumvirate.html

That's a good list. I considered including Git but that could be an entire article by itself. I've looked at TMux but I just don't I'd use it.

What's the difference between Tmux and iTerm2?

Re: Command line tools for the novice

#26
post #20

Earlier quoted context omitted.

Please define "argument expansion".

In many (all?) unix shells, globs are expanded by the shell before being passed to the program. 'ls *.jpg' is passed expanded to 'ls 1.jpg 2.jpg 3.jpg' BEFORE ls is run. This choice means that if a program wants to use another style of regular expression (ie: pcre), it must be enclosed in quotes on the shell, ie: "ls | grep -P '.*jpg'"

Yes, that's globbing, but I was wondering what the OP meant by argument expansion. It could be just globbing, or include globbing but extend to variable expansion, braces, command substitution... It's hard to put a case that having the shell do these things is the right way to do it without understanding the OP's point clearly.

Re: Command line tools for the novice

#27
post #20

Earlier quoted context omitted.

Please define "argument expansion".

In many (all?) unix shells, globs are expanded by the shell before being passed to the program. 'ls *.jpg' is passed expanded to 'ls 1.jpg 2.jpg 3.jpg' BEFORE ls is run. This choice means that if a program wants to use another style of regular expression (ie: pcre), it must be enclosed in quotes on the shell, ie: "ls | grep -P '.*jpg'"

Minor point: if the glob doesn't match it isn't expanded. Sometimes useful. I rarely escape scp commands for instance.

Re: Command line tools for the novice

#28
post #21

> In Grep grep -R 'some term' * , in Ack ack 'some term'. The -R tells grep to search through all directories and subdirectories while the * tells it what types of files. No, that's not how it works with grep. The shell is expanding the glob * to all the things in the current directory that don't start with a dot and that's what grep sees. It then reads each of them in turn or if they're a directory it descends into…

I was under the impression that * expanded to all things not starting with a dot in all directories-- or better: in each directory that -R dictates. I understand that "* tells it what types of files," isn't correct, but I don't understand what you mean by "plays no further part in the descent."

Re: Command line tools for the novice

#29
post #28
post #21

> In Grep grep -R 'some term' * , in Ack ack 'some term'. The -R tells grep to search through all directories and subdirectories while the * tells it what types of files. No, that's not how it works with grep. The shell is expanding the glob * to all the things in the current directory that don't start with a dot and that's what grep sees. It then reads each of them in turn or if they're a directory it descends into…

I was under the impression that * expanded to all things not starting with a dot in all directories-- or better: in each directory that -R dictates. I understand that "* tells it what types of files," isn't correct, but I don't understand what you mean by "plays no further part in the descent."

  $ mkdir x
  $ cd x
  $ echo aa > .y
  $ mkdir y
  $ echo aa > y/z
  $ echo aa > y/.z
  $ grep -r a *
  y/.z:aa
  y/z:aa
Notice that hidden files in the top-level (.y) don't show up, but those in subdirectories (y/.z) do.

It's kind of a gotcha. Fortunately one rarely finds dotfiles in subdirs.

Re: Command line tools for the novice

#30
post #28

Earlier quoted context omitted.

I was under the impression that * expanded to all things not starting with a dot in all directories-- or better: in each directory that -R dictates. I understand that "* tells it what types of files," isn't correct, but I don't understand what you mean by "plays no further part in the descent."

$ mkdir x $ cd x $ echo aa > .y $ mkdir y $ echo aa > y/z $ echo aa > y/.z $ grep -r a * y/.z:aa y/z:aa Notice that hidden files in the top-level (.y) don't show up, but those in subdirectories (y/.z) do. It's kind of a gotcha. Fortunately one rarely finds dotfiles in subdirs.

holy crap - I didn't realize this. Thanks!
Post reply on HN