Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
Pay attention to ";" versus "&&" in bash aliases
Or maybe avoid it altogether, it's probably some sort of well known linux/unix rule that someone wrote a long time ago.
It's possibly something that seldom ever is a problem to anyone, but it was for me.
I had this as an alias for "mv"
Then at some point I was doing an one liner that would scan symlinks' "realpaths" to decide whether to move them or not, and the result was that it was moving regardless of a path being grepped or not, despite of a "dry run" with "echo mv" suggesting otherwise.
That's "obviously" because the ";" instead of "&&", as well as not using if/then/fi to do the checking, but just "grep pattern &&". With that alias, the de facto one liner was then:
In other words, not grepping "pattern" just skipped the echo part of the alias, but still had the "mv" afterwards. With "&&" on the alias it worked, more or less as if it were done with a proper if/then/fi statement, which is possibly preferably the ideal thing to do most of the time.
I'm adding also "&& sleep 1" on the alias, so to force myself actually using "mv -i", or my silent alias, "mvi".
It's possibly something that seldom ever is a problem to anyone, but it was for me.
I had this as an alias for "mv"
Code:
echo "use mv -i to avoid overwriting files with the same name; this is an alias to mv -i" ; mv -i
That's "obviously" because the ";" instead of "&&", as well as not using if/then/fi to do the checking, but just "grep pattern &&". With that alias, the de facto one liner was then:
Code:
grep pattern && echo "warning message on alias" ; mv $file ./folder
I'm adding also "&& sleep 1" on the alias, so to force myself actually using "mv -i", or my silent alias, "mvi".
Total Comments 0