4 ms·
I'm sorry but obviously you had to learn how to use nushell but you didn't learn how to use find (you don't need xargs) or bash (you don't need find). Your fir
by Arch-TK 4y ago
I'm sorry but obviously you had to learn how to use nushell but you didn't learn how to use find (you don't need xargs) or bash (you don't need find).
Your first problem solved in bash:
shopt -s globstar
for f in ./**/data.json; do mv "$f" "${f%json}yml"; done
You can do it without globstar (without running into weird issues with newlines) like so:
find . -name data.json -print0 | while read -rd '' f; do mv "$f" "${f%json}yml"; done
Now, since the particular problem doesn't require a shell at all, you can solve it entirely in find:
find . -name data.json -execdir mv {} data.yml \;
Your second example would be:
(
cd "$(which npm.ps1)" && \
for f in *.ps1; do printf "alias %s='powershell.exe %s'\n" "${f%.ps1}" "$f"; done
) >file
- wodenokoto 4y ago> Now, since the particular problem doesn't require a shell at all, you can solve it entirely in find: find . -name data.json -execdir mv {} data.yml \; How do you do that without a shell?
- maxloh 4y agoIIRC running a command without piping/string semantics doesn't involve a shell, such as os.system() in python and child_process.exec() in Node.js.
- Arch-TK 4y agoI mean obviously you need some way of executing the command and you're probably not going to write a C program to call execve to do it, but the point is that it doesn't involve any shell features and aside from the escape syntax for the semicolon is completely shell independent.
- maxloh 4y agoI didn't learn Bash from scratch. I just serach Google/StackOverflow for similar questions. But that is the point, there are too many commands to do the same job in Bash, each with dozens of flags. It is hard to learn them all, or even find the right command (like shopt, read) or flag (like -rd, print0, -execdir) in the first place. That's why Nutshell will be simpler for small tasks.
- Arch-TK 4y agoNo, the point is that if you go into a discussion saying: "X is better than Y but I should warn you that I never bothered learning Y but instead spent my time learning X" your ability to provide an accurate comparison is already put into question. Then you go on and provide examples of extremely sub-optimal Y code and compare it to X code you wrote. It's very uncharitable and very difficult to tell what is actually better. It doesn't matter if X or Y is better at this point because you haven't provided a fair comparison. And while I agree that bash is shit, I need a lot more than "here's some poorly written bash code compared to nushell" to persuade me to switch to something less ubiquitous. Since bash and presumably nushell are both turing complete, there should be an infinite number of ways of achieving any task, what you want to compare is the shortest but so short that they're difficult to comprehend solutions, and there aren't that many. I can't tell if you picked the most idiomatic nushell solutions to your problems but I can definitely tell you didn't do the same for bash. If you're happy to use nushell you would probably be happy to enable globstar in your shell. So my first solution would be comparable to your nushell version. And yes, you need to know what globstar is, just like you would need to know what nushell is. Given that bash and presumably nushell both support running arbitrary commands the find version is actually shell independent and the fact that you don't know how to use find isn't bash's problem. Let's put it this way, given I don't know nushell, I would also have to learn the iterator, lambda, and variable substitution syntax (each, ||, $v.name). I know how equivalents of those features work in bash (for, $...). I don't find your code any easier to read by default (without having to make guesses as to how nushell works). If I claimed right now that I find nushell syntax to be confusing, weird and unusual, would you think it would be fair for me to say that based on reading only your code?
- 0dayz 4y agoYou miss the part about them saying that the code is from stackoverflow so in other words not exactly hacked together. Overall I agree with both of you but on different points, she'll scripting is an outdated painful process and yes we should provide optimal answers to be fair.
- 4y ago