posix shell alternatives

#2 · closed · 4 comments

View on GitHub ↗

Konfekt

If `Python` is unavailable, the following simple commands using POSIX shell syntax might help out ```sh #!/bin/sh # cpm = cp [all but last arg] [last arg] [last arg].old cpm() { cp "${@:1:$(($# - 1))}" "${@:$#}" "${@:$#}".old; } pm() { mv "${@:1:$(($# - 1))}" "${@:$#}" "${@:$#}".old; } upm() { mv "${1%.[^.]*}".old "${1%.[^.]*}"; } sw() { tmp=$(mktemp) mv "$1" "$tmp" mv "$2" "$1" mv "$tmp" "$2" } ```

Comments

uxcn

These get some of the semantics wrong. I would at very least change the last function... sw() { tmp=$(mktemp) mv "$1" "$tmp" && \ mv "$2" "$1" && \ mv "$tmp" "$2" }

Konfekt

Thank you! Which semantics?

uxcn

No problem. At first glance, all of the arguments you pass to the commands are missing, also lists of files. I've actually thought about re-writing these in `c` just to get rid of the `python` dependency, but it seems like overkill for something not a lot of people use.

Konfekt

Well, the arguments might seem missing, but then again the commands seem to work. Yes, the Python dependency seems overkill, but then again, also rewriting. A posix shell version seems most appropriate, because no dependencies at all and easy installation.