4 ms·
Bash syntax is so alien. The sentence before your example: "The : built-in is used in place of a temporary variable." So I was like wtf even before you spit yo
by lubesGordi 5y ago
Bash syntax is so alien. The sentence before your example: "The : built-in is used in place of a temporary variable." So I was like wtf even before you spit your drink. Maybe someone can claim there's efficiency here?
- chasil 5y agoIt's actually a "no-op" -try it. if [ -z "$foo" ] then : else echo not blank "$foo" fi
- mrspuratic 5y agoIt is intrinsically a nop, but its context can have side effects because it's still a real command. One side effect is exploited here: setting $_ to the last argument of the previous command. The first description in the article of its use is unhelpful, it's not until the end in "Simpler case statement" that it's made clear. I often use it instead of truncate or touch : > somefile : >> somefile : is not lexically special (the way # is), you can use : in variable and function names, even create a function called just ":" if you're trying to confuse...