I'm not a programmer by trade, so the only language I know well is bash. But as sysadmins we do use bash often.

Looking at other sysadmins' scripts though, there are interesting things in it every so often. Like for example `touch file` which creates a file. I've seen some sysadmins just do this instead `> file`. Genius! Or perhaps a `cat file >> elsewhere`. You can do that with `< file >> elsewhere`. It's something that if I hadn't seen it elsewhere, I wouldn't have thought about. But yeah, it saves a program call and it works!

  • 6
    I've been getting into bash lately cos of some devops stuff that's been assigned to me. I gotta say... It's awful and weird and brilliant at the same time. I love it but I feel like I shouldn't.
  • 6
    I don’t see anything genius about “> file” instead of “touch file”. We software developers should strive to make every piece of code easy to understand, in reasonable manner.
  • 1
    I've had a few experiences with bash, but nothing too spectacular.
    Although it's a handy shortcut, I must say that I agree with the others: you won't save a lot of time imo since they're so short and anything longer than ~3 letters can probably be autocompleted if you really want to. You only add complexity and make it less readable for a minimal gain in script size.
    Are there any significant pros for choosing the < & > over their corresponding function names?

    Note: I say this from a dev pov, since I honestly cannot say if a difference of a few characters per line are worth the loss of readability...
  • 1
    Bash is a good language to write obfuscated code in.
    But if you really into obfuscation, go for Brainfuck or Intercal instead.
    Even less readable may be code written in Whitespace using only whitespace characters...
  • 0
    As @aviophile said just use touch for that unless you need some specific content like a pid or timestamp (for backup verification for example, always check contents)
  • 3
    Touch is not the command to create a file. It changes the last modified time stamp of a file. Hence, touch.

    Creating a file is a side effect. Admittedly, 99% of touch's real world use is to create files, but you could argue that '> file' is cleaner. It does not rely on a side effect of a program intended to do something else.
  • 0
    @Oktokolo malbolge...
  • 1
    That looks like a nice language for the next tamper-proofing tool for protecting DRM in commercial software.
    Must be absurdly hard to crack something that has been transcoded to Malbolge...
  • 1
    @aviophile now do that for a fleet of 10.000 servers and you start to realize that CPU time is actually more valuable than development time. Easy to read? Data comes in, data comes out. Can't be easier to me. It's merely something I wouldn't have thought about otherwise.
  • 2
    @NEMESISprj script size or savings in typing aren't what I'm concerned with, nor is it what the original author was (this came from a BGP tutorial iirc). The issue is that touch is an external command that needs to be loaded from disk - another program has to be called. Bash internals are generally better in that regard.
  • 2
    @Condor ohh I didn't know that touch was external and the > was internal. Makes a lot more sense now for me after your explanation, thanks!
Add Comment