|
|
|
|
|
by kayodelycaon
1696 days ago
|
|
> I cannot believe people are parsing text output from other commands in the year 2021 If you're writing shell scripts, there aren't any other options. Here's a lovely little snippet to find the current wifi network for a reMarkable 2. If it's "Aardvark", it runs rsync. :) iw wlan0 info | grep -Po '(?<=ssid ).*' | tr -d '\n'
Ugly as hell? Yes, but what's the alternative?Parsing text from a command is a headache, but it works most of the time. There often isn't an API or syscall to get the data you need on a specific system. My favorite ugly hack is having a Ruby on Rails application write a file to disk so it can be processed by another program using a shell and then picking up the output file after that program finishes. This requires a lot of cleanup and diligence to keep from leaking files... or you can set up a nightly cronjob using find to locate all of the files created more than a week ago and delete them. :) Linux and Unix are a pile of hacks. It isn't going to change anytime soon. |
|