I just discovered something interesting about bash scripts and using them in aliases. I'm posting this for those who use aliases and scripts.
If you're using aliases and you have this exemplary alias:
This turned out to be wrong and causes the shell to go nuts and it stops executing the script commands properly: especially if you've set your terminal to autoexit when the command has been executed successfully AND if the script normally expects any user input from you.
In short my discovery is that you can't have both "exec" and "exit" in the alias at the same time - it has to be either "exec" only or "exit" only.
If you have the alias as in the code above, this causes a... let's call it a "triple exit" of the shell - one exit from the terminal settings, another from the result after the "exec" command and a third exit from the "&& exit" command. And because of that triple exit the shell stops accepting any input words you type after the alias.
Let me give you an example.
In my script the command is
When I run the alias, normally the terminal would expect two inputs from me - the name of the archive ($1) and the version numbers ($2) and the final result would be like "archivename_1.1.1.1.7z"
But I hadn't noticed that "somewhere down the road" I've added an "exit" after the first part of the alias. This caused the script to create a completely different archive: "_.7z". Needless to say this wasn't acceptable for me, so after confirming the script command actually works (outside the alias), it was a matter of time to figure out what was wrong with the alias itself.
Why would anyone need an "exec"? Well, because sometimes, for reasons still unknown to me, some scripts get executed but the terminal doesn't exit on its own, if you're expecting it to do so. So you have two options: adding "exec" or "exit" in the alias line. Which one would work from the first run of the alias - that's something for you to find out bc sometimes "&& exit" doesn't work either. In these cases "exec" before the path does the trick.
If you're using aliases and you have this exemplary alias:
Code:
alias runscript1="exec /path/to/script.sh && exit"
This turned out to be wrong and causes the shell to go nuts and it stops executing the script commands properly: especially if you've set your terminal to autoexit when the command has been executed successfully AND if the script normally expects any user input from you.
In short my discovery is that you can't have both "exec" and "exit" in the alias at the same time - it has to be either "exec" only or "exit" only.
If you have the alias as in the code above, this causes a... let's call it a "triple exit" of the shell - one exit from the terminal settings, another from the result after the "exec" command and a third exit from the "&& exit" command. And because of that triple exit the shell stops accepting any input words you type after the alias.
Let me give you an example.
In my script the command is
Code:
7z a /path/to/$1_$2.7z "$1" -mx=0 -mmt=20
When I run the alias, normally the terminal would expect two inputs from me - the name of the archive ($1) and the version numbers ($2) and the final result would be like "archivename_1.1.1.1.7z"
But I hadn't noticed that "somewhere down the road" I've added an "exit" after the first part of the alias. This caused the script to create a completely different archive: "_.7z". Needless to say this wasn't acceptable for me, so after confirming the script command actually works (outside the alias), it was a matter of time to figure out what was wrong with the alias itself.
Why would anyone need an "exec"? Well, because sometimes, for reasons still unknown to me, some scripts get executed but the terminal doesn't exit on its own, if you're expecting it to do so. So you have two options: adding "exec" or "exit" in the alias line. Which one would work from the first run of the alias - that's something for you to find out bc sometimes "&& exit" doesn't work either. In these cases "exec" before the path does the trick.

