4 ms·
Defining a function for is_file as [[ -f $blah ]]; seems like defining a function for var++ as increment_one() ...
by nemasu 12y ago
Defining a function for is_file as [[ -f $blah ]]; seems like defining a function for var++ as increment_one() ...
- girvo 12y agoI get why that seems silly, and I write shell all day (for provisioning Vagrant machines where I don't need Puppet. I'm still yet to work Ansible properly...), so I know exactly what that command does. But to some of my coworkers who don't write shell very often at all, it would make the script far clearer (which is useful as they need to be able to edit it on the fly) to those who don't know shell
- datashaman 12y agoEncouraging coworkers to learn the proper syntax seems a better choice than hiding it with personally chosen abstractions (albeit more readable).
- girvo 12y agoI don't disagree, but in some contexts that trade off is worth it, in my opinion.
- myg204 12y agoYeah, definitely better to keep it idiomatic. Also: $ test -f "$file" is pretty clear I think.
- lukeschlather 12y agoThe "proper" syntax is dumb. I've never considered writing functions to get around it, but seeing this makes me want to contribute some builtins to bash.
- datashaman 12y agoThe correct answer. ^^^
- klibertp 12y agoYou should strive for better readability for intended audience in every single program you write. It's like writing prose, really. It's ok to write "notes to self" with words shortened to single letters and strange symbols all around the place. It's not ok to do the same in a report from a meeting. You should always remember who you're writing for and write accordingly. Hint: you almost never write for the computer.
- deleted 12y ago[deleted]
- CameronNemo 12y agoThen just use test instead.